#include <bits/stdc++.h>
using namespace std;
string toRC(string x) {
  int pos = 0;
  for (int i = 0; i < x.size(); i++)
    if (x[i] < 'A') {
      pos = i;
      break;
    }
  x.insert(pos, " ");
  string column;
  int col = 0, row = 0;
  int i = 0;
  while (x[i] != ' ') column = column + x[i++];
  i++;
  while (i != x.size()) row = row * 10 + x[i++] - '0';
  for (int i = 0; i < pos; i++) col = col * 26 + x[i] - 64;
  string z;
  z += "R";
  string e;
  while (row != 0) {
    char c;
    c = row % 10 + '0';
    e = c + e;
    row /= 10;
  }
  z += e;
  z += "C";
  e = "";
  while (col != 0) {
    char c;
    c = col % 10 + '0';
    e = c + e;
    col /= 10;
  }
  z += e;
  return z;
}
string fromRC(string x) {
  int i = 1;
  string row;
  while (x[i] != 'C') row = row + x[i++];
  int col = 0;
  i++;
  while (i != x.size()) col = col * 10 + x[i++] - '0';
  string transform = "";
  col--;
  while (col >= 0) {
    char e = 65 + col % 26;
    col = col / 26;
    col--;
    string o;
    o = e;
    transform = o + transform;
  }
  if (transform.size() == 0) transform = "A";
  transform += row;
  return transform;
}
int main() {
  int n;
  cin >> n;
  string x;
  string out[100000];
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x[0] == 'R' && x[1] < 'A' && x.find('C') != -1)
      out[i] = fromRC(x);
    else
      out[i] = toRC(x);
  }
  for (int i = 0; i < n; i++) cout << out[i] << endl;
  return 0;
}
