def generate_99_bottles(): bottles = 99 lines = [] while bottles > 0: lines.append(f"{bottles} bottles of beer on the wall, {bottles} bottles of beer.") lines.append("Take one down and pass it around,") if bottles == 1: lines.append("No more bottles of beer on the wall.") else: lines.append(f"{bottles - 1} bottles of beer on the wall.") lines.append("") # Empty line between verses bottles -= 1 lines.append("No more bottles of beer on the wall, no more bottles of beer.") lines.append("Go to the store and buy some more, 99 bottles of beer on the wall.") return '\n'.join(lines) ninety_nine_bottles = generate_99_bottles() N = int(input()) S = input().strip() if S == "Hello, World!": print("H") elif S == ninety_nine_bottles: print("9") elif len(S) > 0 and S[0] == 'Q': # Check if all characters after the first are not HQ+9 commands valid = True for c in S[1:]: if c in {'H', 'Q', '9', '+'}: valid = False break if valid: print(S) else: print(-1) else: print(-1)