#include <bits/stdc++.h>
using namespace std;
bool isdigit(char c) { return ((c <= '9') && (c >= '0')); }
bool isalpha(char c) { return ((c <= 'Z') && (c >= 'A')); }
int str2int(string s) { return atoi(s.c_str()); }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    bool isfirst;
    int ak = 0;
    while (isalpha(s[ak])) {
      ++ak;
    }
    int dk = ak;
    while (dk < ((int)s.size()) && isdigit(s[dk])) {
      ++dk;
    }
    if (dk == ((int)s.size())) {
      int res = 1;
      int mul = 1;
      int delta = 0;
      for (int j = ak - 1; j >= 0; --j) {
        res += mul * (s[j] - 'A');
        if (mul > 1) delta += mul;
        mul *= 26;
      }
      res += delta;
      cout << "R" << s.substr(ak, dk - ak) << "C" << res << endl;
    } else {
      int st = dk + 1;
      int num = str2int(s.substr(st, ((int)s.size()) - st)) - 1;
      int mul = 26;
      int delta = 0;
      int numd = 1;
      while (num > delta + mul) {
        ++numd;
        delta += mul;
        mul *= 26;
      }
      num -= delta;
      string res(numd, '0');
      for (int j = 1; j <= numd; ++j) {
        char c = 'A' + num % 26;
        res[numd - j] = c;
        num /= 26;
      }
      cout << res << s.substr(ak, dk - ak) << endl;
    }
  }
  return 0;
}
