import math def generate_99_bottles_lyrics(): lyrics = [] for n in range(99, -1, -1): if n > 0: bottles_current = f"{n} bottle{'s' if n != 1 else ''} of beer" line1 = f"{bottles_current} on the wall, {bottles_current}." if n == 1: line2 = "Take one down and pass it around, no more bottles of beer on the wall." else: next_n = n - 1 bottles_next = f"{next_n} bottle{'s' if next_n != 1 else ''} of beer" line2 = f"Take one down and pass it around, {bottles_next} on the wall." else: line1 = "No more bottles of beer on the wall, no more bottles of beer." line2 = "Go to the store and buy some more, 99 bottles of beer on the wall." verse = f"{line1}\n{line2}\n" lyrics.append(verse) return ''.join(lyrics) n = int(input()) s = input().strip() hello = "Hello, World!" if s == hello: print("H") elif s == "Q": print("Q") elif s == generate_99_bottles_lyrics(): print("9") elif all(c == 'Q' for c in s): m = len(s) root = math.isqrt(m) if root * root == m: print('Q' * root) else: print(-1) else: print(-1)