while 1:
    try:
        ss=input()
        n=int(input())
        mm=0
        ans=ss[:n]
        for i in range(len(ss)-n+1):
            s=ss[i:i+n]
            m=s.count("C")+s.count("G")
            if m>mm:
                mm=m
                ans=s
        
        print(ans)
    except:
        break