n=int(input()) s=input() if s.count("Q")==1 and s.count("H")==0 and s.count("9")==0: print(s) elif s.count("Q")!=0: for i in range(2,n+1): if n%i==0: for j in range(n//i): if s[(n//i)*j:(n//i)*(j+1)]!=s[(n//i)*(j+1):(n//i)*(j+2)]: break else: print(s[:(n//i)]) break else: print(-1) else: print(-1)