#include <bits/stdc++.h>
using namespace std;
long long num(string str) {
  long long out = 0;
  for (int i = 0; i < str.length(); i++) {
    out *= 26;
    out += str.at(i) - 'A' + 1;
  }
  return out;
}
string pb26(long long n) {
  string reverse = "";
  while (n > 0) {
    int d = (n - 1) % 26 + 1;
    char c = d + 'A' - 1;
    reverse.push_back(c);
    n -= d;
    n /= 26;
  }
  string out = "";
  for (int i = reverse.length() - 1; i > -1; i--) out.push_back(reverse.at(i));
  return out;
}
int main() {
  long long N;
  cin >> N;
  for (int t = 0; t < N; t++) {
    string S;
    cin >> S;
    bool rc = S.at(0) == 'R';
    if (rc) {
      int i = 0;
      while (i < S.length() && S.at(i) != 'C') i++;
      rc = i < S.length() && i > 1;
      if (rc) {
        for (int j = 1; j < i && rc; j++) {
          char c = S.at(j);
          if (c < '0' || c > '9') rc = false;
        }
        if (rc) {
          long long row = stoll(S.substr(1, i - 1)),
                    col = stoll(S.substr(i + 1));
          cout << pb26(col) << row << "\n";
        }
      }
    }
    if (!rc) {
      int i = 0;
      while (true) {
        char c = S.at(i);
        if (c >= '0' && c <= '9') break;
        i++;
      }
      string col = S.substr(0, i);
      long long row = stoll(S.substr(i));
      cout << "R" << row << "C" << num(col) << "\n";
    }
  }
}
