#include <bits/stdc++.h>
using namespace std;
void convert(string);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n;
  while (n--) {
    cin >> s;
    convert(s);
  }
  exit(0);
}
void convert(string s) {
  size_t sc = s.find('C');
  if (s[0] == 'R' && s[1] <= '9' && sc != s.npos) {
    size_t i = 1;
    int r = 0, c = 0;
    for (; i != sc; i++) {
      r = r * 10 + s[i] - '0';
    }
    for (i++; i < s.size(); i++) {
      c = c * 10 + s[i] - '0';
    }
    string rs = "";
    while (c > 0) {
      rs = (char)('A' + (c - 1) % 26) + rs;
      if (!(c % 26)) {
        c -= 26;
      }
      c /= 26;
    }
    cout << rs << r << endl;
  } else {
    size_t i = 0;
    int r = 0, c = 0;
    for (; isalpha(s[i]); i++) r = r * 26 + s[i] - 'A' + 1;
    for (; i < s.size(); i++) c = c * 10 + s[i] - '0';
    cout << "R" << c << "C" << r << endl;
  }
}
