#include <bits/stdc++.h>
using namespace std;
int n;
string a;
void convA() {
  int c = 0, r = 0;
  int i;
  for (i = 1; a[i] != 'C'; i++) {
    r *= 10;
    r += a[i] - '0';
  }
  i++;
  for (; i < a.size(); i++) {
    c *= 10;
    c += a[i] - '0';
  }
  vector<int> ans;
  while (c != 0) {
    if (c % 26 == 0) {
      ans.push_back(26);
      c--;
    } else
      ans.push_back(c % 26);
    c /= 26;
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    char ab = ans[i] + ('A' - 1);
    cout << ab;
  }
  cout << r;
  cout << endl;
}
void convB() {
  vector<int> ans;
  int i;
  for (i = 0; a[i] >= 'A' && a[i] <= 'Z'; i++) {
    if (a[i] == 'Z')
      ans.push_back(26);
    else
      ans.push_back(a[i] - 'A' + 1);
  }
  int c = 0, r;
  for (int j = 0; j < ans.size(); j++) {
    c += ans[j] * pow(26, ans.size() - j - 1);
  }
  cout << 'R';
  for (; i < a.size(); i++) cout << a[i];
  cout << 'C' << c << endl;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    bool RC = false, k = false;
    if (a.size() >= 4) {
      if (a[0] == 'R' && !(a[1] >= 'A' && a[1] <= 'Z'))
        RC = true;
      else
        RC = false;
      for (int i = 2; RC && i < a.size(); i++) {
        if (a[i] >= 'A' && a[i] <= 'Z' && k) {
          RC = false;
          break;
        }
        if (a[i] == 'C' && !k) k = true;
      }
      if (RC && k) convA();
    }
    if (!RC || !k) convB();
  }
}
