while True: try: s = input() n = int(input()) dic = {} for i in range(len(s[0:1-n])): dic[i] = s[i:i+n].count('G')+s[i:i+n].count('C') dic_sort = sorted(dic.items(), key = lambda item: item[1], reverse=True) index = dic_sort[0][0] print(s[index:index+n]) except: break