def f(x): if 'H' in x: return 1000000 if '9' in x: return 1000000 return x.count('Q') N=int(input()) S=input() for i in range(1,N+1): if N%i: continue F=1 for j in range(i,N,i): for k in range(i): if S[k]!=S[j+k]: F=0 if F: if f(S[:i])*i==N: print(S[:i]) exit() print(-1)