I=input N=int(I()) S=I() b=c=0 for t in S: if t=='H':b=1 if t=='Q':c+=1 R=int(c**0.5) T=S[:0if R<1else N//R] print([-1,T][[S,b,c]==[T*R,0,R]])