while True:
    try:
        #获取输入序列
        x1 = input()
        #获取长度N
        N = int(input())
        #设置计数初值
        d= {}
        for n in range(0,len(x1)-N+1):
            k1 = 0
            for word in x1[n:n+N]:
                if word == 'G' or word == 'C':
                    k1 = k1 + 1
            d[x1[n:n+N]] = k1
        
        list1 = list(sorted(d.items(),key=lambda x:x[1] ,reverse=True))
        print(list1[0][0])
    except:
        break