#include <bits/stdc++.h>
#define N 100000
using namespace std;
int t, a;
vector<string> robot;
string tans;
int solve(int idx, string ans, set<int> skip) {
set<char> ch;
if (idx > 1000) {
tans = ans;
return 0;
}
for (int i = 0; i < a; i++) {
if(skip.find(i) != skip.end())
continue;
if (idx < robot[i].length()) {
ch.insert(robot[i][idx]);
} else {
ch.insert(robot[i][idx % robot[i].length()]);
}
}
if (ch.size() == 0)
return 0;
if (ch.size() == 3)
return 0;
if (ch.size() == 1) {
switch (*ch.begin()) {
case 'R':
ans += "P";
break;
case 'P':
ans += "S";
break;
case 'S':
ans += "R";
}
tans = ans;
return 1;
}
char curr[501];
int i = 0;
for (auto xx : ch) {
curr[i++] = xx;
}
string cur(curr);
if(cur.compare("PR") == 0){
for (int i = 0; i < a; i++) {
if (robot[i][idx % robot[i].length()] == 'R') {
skip.insert(i);
}
}
return solve(idx + 1, ans + "P", skip);
}
if (cur.compare("RS") == 0){
for (int i = 0; i < a; i++) {
if (robot[i][idx % robot[i].length()] == 'S') {
skip.insert(i);
}
}
return solve(idx + 1, ans + "R", skip);
}
if (cur.compare("PS") == 0){
for (int i = 0; i < a; i++) {
if (robot[i][idx % robot[i].length()] == 'P') {
skip.insert(i);
}
}
return solve(idx + 1, ans + "S", skip);
}
return 0;
}
int main() {
// your code goes here
int tc = 1;
string s;
string ans;
cin >> t;
while (t--) {
cin >> a;
tans = ans = "";
for (int i = 0; i < a; i++) {
cin >> s;
robot.push_back(s);
}
set<int> st;
int x = solve(0, ans, st);
if (x) {
cout << "Case #" << tc++ << ": " << tans << "\n";
} else {
cout << "Case #" << tc++ << ": IMPOSSIBLE"
<< "\n";
}
robot.clear();
st.clear();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIE4gMTAwMDAwCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHQsIGE7CnZlY3RvcjxzdHJpbmc+IHJvYm90OwoKc3RyaW5nIHRhbnM7CgppbnQgc29sdmUoaW50IGlkeCwgc3RyaW5nIGFucywgc2V0PGludD4gc2tpcCkgewoKICBzZXQ8Y2hhcj4gY2g7CgogIGlmIChpZHggPiAxMDAwKSB7CiAgICB0YW5zID0gYW5zOwogICAgcmV0dXJuIDA7CiAgfQogIGZvciAoaW50IGkgPSAwOyBpIDwgYTsgaSsrKSB7CiAgICAKICAgIGlmKHNraXAuZmluZChpKSAhPSBza2lwLmVuZCgpKQogICAgICAgIGNvbnRpbnVlOwogICAgCiAgICBpZiAoaWR4IDwgcm9ib3RbaV0ubGVuZ3RoKCkpIHsKICAgICAgY2guaW5zZXJ0KHJvYm90W2ldW2lkeF0pOwogICAgfSBlbHNlIHsKICAgICAgY2guaW5zZXJ0KHJvYm90W2ldW2lkeCAlIHJvYm90W2ldLmxlbmd0aCgpXSk7CiAgICB9CiAgfQoKICBpZiAoY2guc2l6ZSgpID09IDApCiAgICByZXR1cm4gMDsKCiAgaWYgKGNoLnNpemUoKSA9PSAzKQogICAgcmV0dXJuIDA7CgogIGlmIChjaC5zaXplKCkgPT0gMSkgewogICAgc3dpdGNoICgqY2guYmVnaW4oKSkgewogICAgY2FzZSAnUic6CiAgICAgIGFucyArPSAiUCI7CiAgICAgIGJyZWFrOwoKICAgIGNhc2UgJ1AnOgogICAgICBhbnMgKz0gIlMiOwogICAgICBicmVhazsKCiAgICBjYXNlICdTJzoKICAgICAgYW5zICs9ICJSIjsKICAgIH0KICAgIHRhbnMgPSBhbnM7CiAgICByZXR1cm4gMTsKICB9CiAgY2hhciBjdXJyWzUwMV07CiAgaW50IGkgPSAwOwogIGZvciAoYXV0byB4eCA6IGNoKSB7CiAgICBjdXJyW2krK10gPSB4eDsKICB9CgogIHN0cmluZyBjdXIoY3Vycik7CgogIGlmKGN1ci5jb21wYXJlKCJQUiIpID09IDApewogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhOyBpKyspIHsKCiAgICAgIGlmIChyb2JvdFtpXVtpZHggJSByb2JvdFtpXS5sZW5ndGgoKV0gPT0gJ1InKSB7CiAgICAgICAgc2tpcC5pbnNlcnQoaSk7CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBzb2x2ZShpZHggKyAxLCBhbnMgKyAiUCIsIHNraXApOwogIH0KICAgIAoKICBpZiAoY3VyLmNvbXBhcmUoIlJTIikgPT0gMCl7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGE7IGkrKykgewoKICAgICAgaWYgKHJvYm90W2ldW2lkeCAlIHJvYm90W2ldLmxlbmd0aCgpXSA9PSAnUycpIHsKICAgICAgICBza2lwLmluc2VydChpKTsKICAgICAgfQogICAgfQogICAgcmV0dXJuIHNvbHZlKGlkeCArIDEsIGFucyArICJSIiwgc2tpcCk7CiAgfQogICAgCgogIGlmIChjdXIuY29tcGFyZSgiUFMiKSA9PSAwKXsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYTsgaSsrKSB7CgogICAgICBpZiAocm9ib3RbaV1baWR4ICUgcm9ib3RbaV0ubGVuZ3RoKCldID09ICdQJykgewogICAgICAgIHNraXAuaW5zZXJ0KGkpOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc29sdmUoaWR4ICsgMSwgYW5zICsgIlMiLCBza2lwKTsKICB9CgogICAgcmV0dXJuIDA7Cn0KCmludCBtYWluKCkgewogIC8vIHlvdXIgY29kZSBnb2VzIGhlcmUKICBpbnQgdGMgPSAxOwogIHN0cmluZyBzOwogIHN0cmluZyBhbnM7CgogIGNpbiA+PiB0OwoKICB3aGlsZSAodC0tKSB7CiAgICBjaW4gPj4gYTsKICAgIHRhbnMgPSBhbnMgPSAiIjsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYTsgaSsrKSB7CiAgICAgIGNpbiA+PiBzOwogICAgICByb2JvdC5wdXNoX2JhY2socyk7CiAgICB9CiAgICBzZXQ8aW50PiBzdDsKICAgIGludCB4ID0gc29sdmUoMCwgYW5zLCBzdCk7CgogICAgaWYgKHgpIHsKICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCB0YysrIDw8ICI6ICIgPDwgdGFucyA8PCAiXG4iOwogICAgfSBlbHNlIHsKICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCB0YysrIDw8ICI6IElNUE9TU0lCTEUiCiAgICAgICAgICAgPDwgIlxuIjsKICAgIH0KICAgIHJvYm90LmNsZWFyKCk7CiAgICBzdC5jbGVhcigpOwogIH0KCiAgcmV0dXJuIDA7Cn0K