n = int(input()) s = input() x = 0 ng = False for c in s: if c == 'Q': x += 1 if c == 'H' or c == '9': ng = True if x == 1 and not ng: print(s) elif x == n: k = 2 while int(pow(k,k)) < n: k += 1 if int(pow(k,k)) == n: print('Q'*k) else: print(-1) else: print(-1)