#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<string> v;
    vector<long long int> num;
    string fi = "";
    for (int i = 0; i < s.length(); ++i) {
      while (s[i] >= 'A' && s[i] <= 'Z') {
        fi += s[i];
        i++;
      }
      if (fi.length()) v.push_back(fi);
      fi = "";
    }
    long long int n = 0;
    for (int i = 0; i < s.length(); ++i) {
      while (s[i] >= '0' && s[i] <= '9') {
        n = n * 10;
        n += s[i] - '0';
        i++;
      }
      if (n) num.push_back(n);
      n = 0;
    }
    if (v.size() == 2) {
      long long int row = num[0];
      long long int col = num[1];
      string out = "";
      while (col) {
        long long int rem = col % 26;
        if (rem == 0) {
          rem = 26;
          col -= 26;
        }
        out += 'A' + rem - 1;
        col = col / 26;
      }
      reverse(out.begin(), out.end());
      cout << out << row << endl;
    } else {
      cout << "R" << num[0];
      string temp = v[0];
      long long int mul = 1;
      long long int out = 0;
      for (int i = temp.length() - 1; i >= 0; i--) {
        long long int val = s[i] - 'A' + 1;
        out += val * mul;
        mul *= 26;
      }
      cout << "C" << out << endl;
    }
  }
}
