while True:
try:
s, n = input(), int(input())
if n >= len(s):
print(s)
else:
Max, beg, end = 0, 0, 0
for i in range(len(s)-n):
count = s[i:i+n].count('C') + s[i:i+n].count('G')
if count > Max:
Max = count
beg, end = i, i+n
print(s[beg:end])
except:
break