while True:
    try:
        a = input()
        n = int(input())
        res = []
        d = {}
        s = []
        #取出所有子序列
        for i in range(len(a)-n+1): #注意i的取值范围,保证不能取到短于n的序列
            res.append(a[i:i+n])
        #计算CG比
        for j in res:
            ng = j.count('G')
            nc = j.count('C')
            d[j] = (ng+nc)/len(j)
        #找到最大CG比的子序列
        maxi = max(d.values())
        for j in res:
            if d[j] == maxi:
                s.append(j)
        #输出最先出现的
        print(s[0])
            
    except:
        break