using System; using System.Linq; class I { static void Main() => Console.WriteLine(Solve()); static object Solve() { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); if (s.Contains('H')) return -1; if (!s.Contains('Q')) return -1; var qc = s.Count(c => c == 'Q'); var rc = (int)Math.Round(Math.Sqrt(qc)); if (rc * rc != qc) return -1; if (n % rc != 0) return -1; var sublength = n / rc; var sub = s[..sublength]; for (int i = 0; i < rc; i++) if (s[(i * sublength)..((i + 1) * sublength)] != sub) return -1; return sub; } }