def generate_h_str(): return "Hello, World!" def generate_nine_str(): s = [] for i in range(99, 0, -1): s.append(f"{i} bottle{'s' if i != 1 else ''} of beer on the wall, {i} bottle{'s' if i != 1 else ''} of beer.") s.append(f"Take one down and pass it around, {i-1 if i-1 != 0 else 'no more'} bottle{'s' if (i-1) != 1 else ''} of beer on the wall.") s.append("") s.append("No more bottles of beer on the wall, no more bottles of beer.") s.append("Go to the store and buy some more, 99 bottles of beer on the wall.") return '\n'.join(s) H_STR = generate_h_str() NINE_STR = generate_nine_str() n = int(input()) s = input().strip() if s == H_STR: print("H") elif s == NINE_STR: print("9") elif s == "Q": print("Q") else: # Check if all characters are 'Q's and length is a perfect square all_q = True for c in s: if c != 'Q': all_q = False break if all_q: m = int(len(s) ** 0.5) if m * m == len(s): print('Q' * m) exit() # Check if exactly one 'Q' and no 'H' or '9' q_count = 0 h_count = 0 nine_count = 0 for c in s: if c == 'Q': q_count += 1 elif c == 'H': h_count += 1 elif c == '9': nine_count += 1 if q_count == 1 and h_count == 0 and nine_count == 0: print(s) exit() # None of the cases matched print(-1)