#include <bits/stdc++.h>
using namespace std;
void solve(string& s) {
  int rpos = s.find('R');
  int cpos = s.find('C');
  bool sf = false;
  if ((rpos != -1) && (cpos != -1) && (cpos - rpos > 1)) {
    int i = rpos + 1;
    while (i != cpos && s[i] >= '0' && s[i] <= '9') i++;
    sf = i == cpos;
  }
  if (sf) {
    string rnum = s.substr(rpos + 1, cpos - rpos - 1);
    string cnum = s.substr(cpos + 1, s.length());
    int c = atoi(cnum.c_str());
    char ch[64] = {0};
    int i = 62;
    while (c) {
      char cr = (c - 1) % 26 + 'A';
      ch[i--] = cr;
      c = (c - 1) / 26;
    }
    printf("%s%s\n", ch + i + 1, rnum.c_str());
  } else {
    int i = 0;
    while (i != s.length() && (s[i] < '0' || s[i] > '9')) i++;
    string cnum = s.substr(0, i);
    string rnum = s.substr(i, s.length() - i);
    int sum = 0;
    int p = 1;
    for (int j = cnum.length() - 1; j >= 0; --j) {
      sum += p * (cnum[j] - 'A' + 1);
      p *= 26;
    }
    printf("R%sC%d\n", rnum.c_str(), sum);
  }
}
int main() {
  int n;
  n = 1;
  cin >> n;
  string s;
  while (n--) {
    cin >> s;
    solve(s);
  }
  return 0;
}
