n = int(input()) S = input() for s in S: if s == "9" or s == "H": print(-1) exit() q = S.count("Q") if q == 0: print(-1) exit() for i in range(10**3): if i*i == q: break else: print(-1) exit() if n%i: print(-1) exit() m = n//i P = S[:m] if P.count("Q") != i: print(-1) exit() if S == P*i: print(P) else: print(-1)