#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
  int n;
  cin >> n;
  while (n--) {
    string second;
    cin >> second;
    if (second[0] == 'R' && isdigit(second[1])) {
      int r = 0, c = 0;
      bool ok = true;
      for (int i = 1; i < int((second).size()); ++i) {
        if (isdigit(second[i]) && ok)
          r = r * 10 + second[i] - '0';
        else {
          if (second[i] == 'C') {
            ok = false;
            continue;
          }
          if (!ok) c = c * 10 + second[i] - '0';
        }
      }
      if (ok) {
        r = 0;
        c = 0;
        for (int i = 0; i < int((second).size()); ++i)
          if (isdigit(second[i]))
            r = r * 10 + second[i] - '0';
          else
            c = c * 26 + (second[i] - 'A' + 1);
        cout << 'R' << r << 'C' << c << endl;
        continue;
      }
      string ans = "";
      while (c) {
        ans = char(((c - 1) % 26) + 'A') + ans;
        c = (c - 1) / 26;
      }
      cout << ans << r << endl;
    } else {
      int r = 0, c = 0;
      for (int i = 0; i < int((second).size()); ++i)
        if (isdigit(second[i]))
          r = r * 10 + second[i] - '0';
        else
          c = c * 26 + (second[i] - 'A' + 1);
      cout << 'R' << r << 'C' << c << endl;
    }
  }
  return 0;
}
