#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;
}
