import sys input = sys.stdin.readline #N,M = map(int,input().split()) #print(N) N = int(input()) S = input().rstrip() if S.count("Q")==1 and \ "H" not in S and \ "9" not in S: print(S) elif S.count("Q")==N: m = 0 n = 1 while m*m < N: m += 1 if m*m==N: print("Q"*m) else: print(-1) else: print(-1)