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