w = input()
n = int(input())
wn = ['A', 'C', 'G', 'T']
b = []
for i in range(len(w)):
if i+n != len(w):
x = w[i:i+n]
b.append([x, (x.count('C')+x.count('G'))/n])
x = []
elif i+n == len(w):
x = w[i:i+n]
b.append([x, (x.count('C')+x.count('G'))/n])
break
# b = sorted(b, key=lambda x:x[1], reverse=True)
b.sort(key=lambda x:x[1], reverse=True)
print(b[0][0])
n = int(input())
wn = ['A', 'C', 'G', 'T']
b = []
for i in range(len(w)):
if i+n != len(w):
x = w[i:i+n]
b.append([x, (x.count('C')+x.count('G'))/n])
x = []
elif i+n == len(w):
x = w[i:i+n]
b.append([x, (x.count('C')+x.count('G'))/n])
break
# b = sorted(b, key=lambda x:x[1], reverse=True)
b.sort(key=lambda x:x[1], reverse=True)
print(b[0][0])