import sys
input = sys.stdin.readline

#N,M = map(int,input().split())
#print(N)

N = int(input())
S = input().rstrip()

nQ = S.count("Q")
if "H" in S or \
   "9" in S:
	print(-1)

elif nQ==1:
	print(S)

elif nQ>1:
	m = 0
	while m*m < nQ:
		m += 1
	if m*m==nQ:
		T = S[:(N//m)]
		if T*m == S:
			print(T)
		else:
			print(-1)
	else:
		print(-1)
else:
	print(-1)