#include <bits/stdc++.h>
using namespace std;
void process(string cur) {
  int r, c;
  string row, col;
  int cpos;
  bool type = (cur[0] == 'R') && (cur[1] <= '9' && cur[1] >= '0');
  bool flag = true;
  if (type) {
    for (int i = 2; i < cur.length(); i++) {
      if (cur[i] == 'C') {
        flag = false;
        cpos = i;
        break;
      }
    }
  }
  if (flag) type = false;
  if (type) {
    row = cur.substr(1, cpos - 1);
    col = cur.substr(cpos + 1, cur.length() - cpos - 1);
    c = 0;
    for (int i = 0; i < col.length(); i++) {
      c *= 10;
      c += (int)(col[i] - '0');
    }
    string colout = "";
    char out;
    while (c > 0) {
      if (c % 26 == 0) {
        c -= 1;
        out = 'Z';
      } else {
        out = (c % 26 - 1 + 'A');
      }
      colout = out + colout;
      c /= 26;
    }
    cout << colout << row << endl;
  } else {
    for (int i = 0; i < cur.length(); i++) {
      if ((cur[i] <= '9') && (cur[i] >= '0')) {
        cpos = i;
        break;
      }
    }
    row = cur.substr(cpos, cur.length() - cpos);
    col = cur.substr(0, cpos);
    c = 0;
    for (int i = 0; i < col.length(); i++) {
      c *= 26;
      c += (int)(col[i] - 'A');
      c++;
    }
    cout << 'R' << row << 'C' << c << endl;
  }
}
int main() {
  int n;
  cin >> n;
  string current;
  getline(cin, current);
  for (int i = 0; i < n; i++) {
    getline(cin, current);
    process(current);
  }
  return 0;
}
