while True:
    try:

        in_str = input()
        num = int(input())
        res = ''
        a_max = 0
        for i in range(len(in_str) -num+1):
            a = in_str[i:i+num].count('G')+in_str[i:i+num].count('C')
            if a_max <a :
                a_max = a  
                res = in_str[i:i+num]

        print(res)
    except:
        pass
while True:
    try:
        s=input()
        n=int(input())
        res=0
        index=0
        for i in range(0,len(s)-n+1):
            GC_Ratio=s.count('G',i,i+n)+s.count('C',i,i+n)
            if GC_Ratio>res:
                res=GC_Ratio
                index=i
        print(s[index:index+n])
    except:
        break