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