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) else: print(-1)