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 ng: print(-1) elif x>0: ok = True k = 1 while int(pow(k,k)) < x: k += 1 if int(pow(k,k)) != x or n%k != 0: ok = False m = n//k for i in range(k): if s[i*m:(i+1)*m] != s[0:m]: ok = False break if ok: print(s[0:m]) else: print(-1) else: print(-1)