import math def generate_lyrics(): verses = [] for v in range(99, 0, -1): verses.append(f"{v} bottles of beer on the wall, {v} bottles of beer.") verses.append(f"Take one down and pass it around, {v-1} bottles of beer on the wall.") verses.append('') verses.append("No more bottles of beer on the wall, no more bottles of beer.") verses.append("Go to the store and buy some more, 99 bottles of beer on the wall.") return '\n'.join(verses[:-1]) def check_case1(S): n = len(S) m = int(math.sqrt(n)) if m * m != n: return None P = S[:m] for i in range(m): if S[i*m : (i+1)*m] != P: return None for c in P: if c not in {'H', 'Q'}: return None return P def main(): import sys input = sys.stdin.read().split() N = int(input[0]) S = input[1] if len(input) > 1 else '' result_case1 = check_case1(S) if result_case1 is not None: print(result_case1) return lyrics = generate_lyrics() if S == lyrics: print("9") return print(-1) if __name__ == "__main__": main()