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-1): if s[(n//i)*j:(n//i)*(j+1)]!=s[(n//i)*(j+1):(n//i)*(j+2)]: break else: t=s[:(n//i)] if t.count("Q")==i: print(t) break else: print(-1) else: print(-1)