import math n = int(input()) s = input() cnt = 0 for c in s: if c != "Q": print(-1) exit() else: cnt += 1 m = int(math.sqrt(cnt)) if m ** 2 == cnt and n % m == 0: u = s[0:m] if u * m == s: print(u) else: print(-1) else: print(-1)