#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double PI = 2 * acos(0.0);
const double EPS = 1e-9;
int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a > b ? 1 : 2; }
int DI[] = {-1, 0, 1, 0, 1, -1, -1, 1};
int DJ[] = {0, 1, 0, -1, 1, -1, 1, -1};
void clc1(string x) {
  int idx = x.find('C');
  string r = x.substr(1, idx - 1);
  string c = x.substr(idx + 1);
  int cc = atoi(c.c_str());
  string ans = "";
  while (cc) {
    char d = cc % 26 + 'A' - 1;
    cc /= 26;
    if (d == '@') {
      d = 'Z';
      cc--;
    }
    ans += d;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << r << endl;
}
void clc2(string x) {
  string c = "";
  cout << "R";
  for (int i = 0; i < (int)(int)x.size(); i++) {
    if (isdigit(x[i]))
      cout << x[i];
    else
      c += x[i];
  }
  cout << "C";
  int ans = 0;
  int p = 1;
  for (int i = (int)c.size() - 1; i >= 0; i--) {
    ans += (((c[i] - 'A') + 1) * p);
    p *= 26;
  }
  cout << ans << endl;
}
bool f(string x) {
  if (x[0] != 'R') return 0;
  int r = x.find('C');
  if (r == -1) return 0;
  for (int i = 1; i < r; i++)
    if (isdigit(x[i])) return 1;
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    string x;
    cin >> x;
    if (f(x))
      clc1(x);
    else
      clc2(x);
  }
  return 0;
}
