#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000;
const int mod = 1000 * 1000 + 3;
int toInt(string x) {
  stringstream second;
  second << x;
  int ret;
  second >> ret;
  return ret;
}
string Ex(int x) {
  for (int l = 1, p = 26;; l++, p *= 26)
    if (x <= p) {
      x--;
      string res;
      for (int i = 0; i < l; i++) res += string(1, 'A' + x % 26), x /= 26;
      reverse(res.begin(), res.end());
      return res;
    } else
      x -= p;
}
int rEx(string x) {
  int res = 0;
  for (int l = 1, p = 26; l < x.size(); l++, p *= 26) res += p;
  reverse(x.begin(), x.end());
  for (int i = 0, p = 1; i < x.size(); i++, p *= 26) res += p * (x[i] - 'A');
  return res + 1;
}
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    string s;
    cin >> s;
    int valid = 0;
    for (int i = 0; i < s.size() - 1; i++)
      if ('0' <= s[i] && s[i] <= '9' && s[i + 1] == 'C') valid = i + 1;
    if (valid) {
      int x = toInt(s.substr(1, valid - 1));
      int y = toInt(s.substr(valid + 1));
      cout << Ex(y) << x << endl;
    } else
      for (int i = 0; i < s.size(); i++)
        if ('0' <= s[i] && s[i] <= '9') {
          cout << 'R' << s.substr(i) << 'C' << rEx(s.substr(0, i)) << endl;
          break;
        }
  }
  return 0;
}
