n = int(input()) s = input() def is_square(n): for i in range(1, 1000): if n == i * i: return i return -1 if 'H' not in s: q = s.count('Q') sq = is_square(q) if sq != -1: if n % sq == 0: b = n // sq t = s[0 : b] check = True for l in range(0, n, b): if t != s[l : l + b]: check = False if check: print(t) exit(0) print(-1)