#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> answ;
  for (int i = 0; i < n; i++) {
    bool oot = false;
    string s;
    int sum = 0;
    cin >> s;
    if (s[0] == 'R' && (s[1] >= '1' && s[1] <= '9')) {
      oot = true;
      for (int i = 2; i < s.size(); i++) {
        if (s[i] == 'C') {
          oot = false;
          break;
        }
      }
    } else
      oot = true;
    if (!oot) {
      string sa;
      string substr;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'C') {
          substr = s.substr(1, i - 1);
          sa = s.substr(i + 1, s.length() - 1 - i);
          break;
        }
      }
      reverse(sa.begin(), sa.end());
      int pos = 1;
      int poss = 1;
      long long ans = 0;
      for (int i = 0; i < sa.length(); i++) {
        ans += (sa[i] - '0') * pos;
        pos *= 10;
      }
      string ko;
      while (ans != 0) {
        int rest = (ans - 1) % 26;
        ko = (char)('A' + rest) + ko;
        ans = (ans - rest - 1) / 26;
      }
      answ.push_back(ko + substr);
    } else {
      vector<int> cnt;
      string subStr;
      for (int i = 0; i < s.length(); i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') {
          cnt.push_back(s[i] - 'A' + 1);
        } else {
          subStr = s.substr(i, s.size() - i);
          break;
        }
      }
      long long ans2 = 0;
      int mul = 1;
      reverse(cnt.rbegin(), cnt.rend());
      for (int i = 0; i < cnt.size(); i++) {
        ans2 += cnt[i] * mul;
        mul *= 26;
      }
      char numstr[21];
      sprintf(numstr, "%d", ans2);
      string str = "R" + subStr + "C" + numstr;
      answ.push_back(str);
    }
  }
  for (int i = 0; i < answ.size(); i++) {
    cout << answ[i] << endl;
  }
  return 0;
}
