#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; inline int sqrt(int x) { int y = sqrtl(x); while (y * y > x) --y; while ((y + 1) * (y + 1) <= x) ++y; return y; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; string s; cin >> n >> s; int cnt = 0; for (char c : s) if (c == 'Q') ++cnt; int sq = sqrt(cnt); if (cnt != 0 && sq * sq == cnt) { if (s.size() % sq == 0) { string t = s.substr(0, s.size() / sq); bool ok = true; rep(i, sq) if (s.substr(i * t.size(), t.size()) != t) ok = false; if (t.contains('H')) ok = false; if (ok) { int cnt1 = 0; for (char c : t) if (c == 'Q') ++cnt1; if (cnt1 == sq) { cout << t << '\n'; return 0; } } } } cout << -1 << '\n'; return 0; }