#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <map>
using namespace std;
#define pb push_back
string imp()
{
return "IMPOSSIBLE";
}
// 0 - R
// 1 - P
// 2 - S
const int MAXCNT = 501;
int ccnt[MAXCNT];
int cnt[MAXCNT][3];
void solve()
{
for(int i = 0; i < MAXCNT; i++)
{
ccnt[i] = 0;
for(int j = 0; j < 3; j++)
{
cnt[i][j] = 0;
}
}
int a; cin >> a;
vector<string> opp(a);
for(int i = 0; i < a; i++)
{
cin >> opp[i];
}
for(int i = 0; i < a; i++)
{
string st = opp[i];
int stl = st.size();
for (int j = 0; j < MAXCNT; j++)
{
if (st[j % stl] == 'R')
{
cnt[j][0] += 1;
}
else if (st[j % stl] == 'P')
{
cnt[j][1] += 1;
}
else
{
cnt[j][2] += 1;
}
}
}
for (int i = 0; i < MAXCNT; i++)
{
int temp = 0;
for (int j = 0; j < 3; j++)
if (cnt[i][j] != 0)
temp += 1;
ccnt[i] = temp;
}
map<char,char> mp1;
mp1['R'] = 'P';
mp1['P'] = 'S';
mp1['S'] = 'R';
map<string, char> mp2;
mp2["RP"] = 'P';
mp2["PR"] = 'P';
mp2["RS"] = 'R';
mp2["SR"] = 'R';
mp2["SP"] = 'S';
mp2["PS"] = 'S';
int x1 = 0;
for (int i = 0; i < MAXCNT; i++)
{
if(ccnt[i] == 1)
x1 += 1;
}
if(x1 == 0)
{
cout << imp() << "\n";
return;
}
int x3 = 0;
int i = 0;
while (i < MAXCNT && ccnt[i] != 1)
{
if (ccnt[i] == 3)
x3 += 1;
i += 1;
}
if (x3 >= 1)
{
cout << imp() << "\n";
return;
}
string fans = "";
i = 0;
while (i < MAXCNT && ccnt[i] != 1)
{
string ss = "";
if (cnt[i][0] != 0)
ss.pb('R');
if (cnt[i][1] != 0)
ss.pb('P');
if (cnt[i][2] != 0)
ss.pb('S');
i += 1;
fans.pb(mp2[ss]);
}
char ch;
if (cnt[i][0] != 0)
ch = 'R';
if (cnt[i][1] != 0)
ch = 'P';;
if (cnt[i][2] != 0)
ch = 'S';
fans.pb(mp1[ch]);
cout << fans << "\n";
}
int main()
{
int num_test_cases;
cin >> num_test_cases;
for (int t = 1; t <= num_test_cases; ++t)
{
cout << "Case #" << t << ": ";
solve();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxkZXF1ZT4KI2luY2x1ZGUgPG1hcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgcGIgcHVzaF9iYWNrCnN0cmluZyBpbXAoKQp7CiAgICByZXR1cm4gICJJTVBPU1NJQkxFIjsKfQovLyAwIC0gUiAKLy8gMSAtIFAKLy8gMiAtIFMKY29uc3QgaW50IE1BWENOVCA9IDUwMTsKaW50IGNjbnRbTUFYQ05UXTsKaW50IGNudFtNQVhDTlRdWzNdOwp2b2lkIHNvbHZlKCkKewogICAgZm9yKGludCBpID0gMDsgaSA8IE1BWENOVDsgaSsrKQogICAgewogICAgICAgIGNjbnRbaV0gPSAwOwogICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCAzOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBjbnRbaV1bal0gPSAwOwogICAgICAgIH0KICAgIH0KICAgIGludCBhOyBjaW4gPj4gYTsKICAgIHZlY3RvcjxzdHJpbmc+IG9wcChhKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBhOyBpKyspCiAgICB7CiAgICAgICAgY2luID4+IG9wcFtpXTsKICAgIH0KICAgIGZvcihpbnQgaSA9IDA7IGkgPCBhOyBpKyspCiAgICB7CiAgICAgICAgc3RyaW5nIHN0ID0gb3BwW2ldOwogICAgICAgIGludCBzdGwgPSBzdC5zaXplKCk7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBNQVhDTlQ7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmIChzdFtqICUgc3RsXSA9PSAnUicpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNudFtqXVswXSArPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYgKHN0W2ogJSBzdGxdID09ICdQJykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgY250W2pdWzFdICs9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjbnRbal1bMl0gKz0gMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTUFYQ05UOyBpKyspCiAgICB7CiAgICAgICAgaW50IHRlbXAgPSAwOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgMzsgaisrKQogICAgICAgICAgICBpZiAoY250W2ldW2pdICE9IDApCiAgICAgICAgICAgICAgICB0ZW1wICs9IDE7CiAgICAgICAgY2NudFtpXSA9IHRlbXA7CiAgICB9CgogICAgbWFwPGNoYXIsY2hhcj4gbXAxOwogICAgbXAxWydSJ10gPSAnUCc7CiAgICBtcDFbJ1AnXSA9ICdTJzsKICAgIG1wMVsnUyddID0gJ1InOwogICAgbWFwPHN0cmluZywgY2hhcj4gbXAyOwogICAgbXAyWyJSUCJdID0gJ1AnOwogICAgbXAyWyJQUiJdID0gJ1AnOwogICAgbXAyWyJSUyJdID0gJ1InOwogICAgbXAyWyJTUiJdID0gJ1InOwogICAgbXAyWyJTUCJdID0gJ1MnOwogICAgbXAyWyJQUyJdID0gJ1MnOwogICAgCiAgICAKICAgIGludCB4MSA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IE1BWENOVDsgaSsrKQogICAgewogICAgICAgIGlmKGNjbnRbaV0gPT0gMSkgCiAgICAgICAgICAgIHgxICs9IDE7CiAgICB9CiAgICBpZih4MSA9PSAwKQogICAgewogICAgICAgIGNvdXQgPDwgaW1wKCkgPDwgIlxuIjsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpbnQgeDMgPSAwOwogICAgaW50IGkgPSAwOwogICAgd2hpbGUgKGkgPCBNQVhDTlQgJiYgY2NudFtpXSAhPSAxKQogICAgewogICAgICAgIGlmIChjY250W2ldID09IDMpCiAgICAgICAgICAgIHgzICs9IDE7CiAgICAgICAgaSArPSAxOwogICAgfQogICAgaWYgKHgzID49IDEpCiAgICB7CiAgICAgICAgY291dCA8PCBpbXAoKSA8PCAiXG4iOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIHN0cmluZyBmYW5zID0gIiI7CiAgICBpID0gMDsKICAgIHdoaWxlIChpIDwgTUFYQ05UICYmIGNjbnRbaV0gIT0gMSkKICAgIHsKICAgICAgICBzdHJpbmcgc3MgPSAiIjsKICAgICAgICBpZiAoY250W2ldWzBdICE9IDApCiAgICAgICAgICAgIHNzLnBiKCdSJyk7CiAgICAgICAgaWYgKGNudFtpXVsxXSAhPSAwKQogICAgICAgICAgICBzcy5wYignUCcpOwogICAgICAgIGlmIChjbnRbaV1bMl0gIT0gMCkKICAgICAgICAgICAgc3MucGIoJ1MnKTsKICAgICAgICBpICs9IDE7CiAgICAgICAgZmFucy5wYihtcDJbc3NdKTsKICAgIH0KICAgIGNoYXIgY2g7CiAgICBpZiAoY250W2ldWzBdICE9IDApCiAgICAgICAgY2ggPSAnUic7CiAgICBpZiAoY250W2ldWzFdICE9IDApCiAgICAgICAgY2ggPSAnUCc7OwogICAgaWYgKGNudFtpXVsyXSAhPSAwKQogICAgICAgIGNoID0gJ1MnOwogICAgZmFucy5wYihtcDFbY2hdKTsKICAgIGNvdXQgPDwgZmFucyA8PCAiXG4iOwp9CgppbnQgbWFpbigpCnsKICAgIGludCBudW1fdGVzdF9jYXNlczsKICAgIGNpbiA+PiBudW1fdGVzdF9jYXNlczsKICAgIGZvciAoaW50IHQgPSAxOyB0IDw9IG51bV90ZXN0X2Nhc2VzOyArK3QpCiAgICB7CiAgICAgICAgY291dCA8PCAiQ2FzZSAjIiA8PCB0IDw8ICI6ICI7CiAgICAgICAgc29sdmUoKTsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==