#include <bits/stdc++.h>
using namespace std;
char str[10000];
string to_str(int n) {
  string r;
  int len = 1, p26 = 26;
  while (n > p26) {
    n -= p26;
    p26 *= 26;
    len++;
  }
  n--;
  while (len) {
    r.push_back((n % 26) + 'A');
    n /= 26;
    len--;
  }
  reverse(r.begin(), r.end());
  return r;
}
int from_str(string s) {
  int r = 0;
  int len = 1, p26 = 26;
  while (len < s.length()) {
    r += p26;
    p26 *= 26;
    len++;
  }
  int num = 0;
  for (int i = 0; i < s.length(); i++) {
    num = 26 * num + s[i] - 'A';
  }
  return num + r + 1;
}
int main() {
  int t;
  scanf("%d", &t);
  getchar();
  while (t--) {
    scanf("%s", str);
    int x1, y1;
    if (sscanf(str, "R%dC%d", &x1, &y1) == 2) {
      cout << to_str(y1) << x1 << endl;
    } else {
      char *p = str;
      while (!isdigit(*p)) p++;
      char c = *p;
      *p = 0;
      y1 = from_str(str);
      *p = c;
      cout << "R" << p << "C" << y1 << endl;
    }
  }
  return 0;
}
