#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s[230];
bool isch(char x) { return 'A' <= x && x <= 'Z'; }
bool isnum(char x) { return '0' <= x && x <= '9'; }
int y, x, len;
int gettype() {
  len = strlen(s);
  int cnt = 0;
  for (int i = 1; i < len; i++) {
    if (isch(s[i - 1]) && isnum(s[i]) || isch(s[i]) && isnum(s[i - 1])) {
      cnt++;
    }
  }
  if (cnt == 1) return 1;
  return 2;
}
void work1() {
  int p;
  for (int i = 1; i < len; i++) {
    if (isch(s[i - 1]) && isnum(s[i])) {
      p = i - 1;
      break;
    }
  }
  y = 0;
  for (int i = 0; i <= p; i++) {
    int t = s[i] - 'A' + 1;
    y = 26 * y + t;
  }
  x = 0;
  for (int i = p + 1; i < len; i++) {
    int t = s[i] - '0';
    x = 10 * x + t;
  }
}
void work2() {
  int p;
  for (int i = 1; i < len; i++) {
    if (isch(s[i]) && isnum(s[i - 1])) {
      p = i - 1;
      break;
    }
  }
  x = 0;
  for (int i = 1; i <= p; i++) {
    int t = s[i] - '0';
    x = 10 * x + t;
  }
  y = 0;
  for (int i = p + 2; i < len; i++) {
    int t = s[i] - '0';
    y = 10 * y + t;
  }
}
void write2() {
  string ans = "R";
  string tmp = "";
  int t = x;
  while (t) {
    int k = t % 10;
    tmp = char('0' + k) + tmp;
    t /= 10;
  }
  ans += tmp;
  ans += "C";
  t = y;
  tmp = "";
  while (t) {
    int k = t % 10;
    tmp = char('0' + k) + tmp;
    t /= 10;
  }
  ans += tmp;
  cout << ans << endl;
}
void write1() {
  string ans = "";
  string tmp = "";
  int t = y;
  while (t) {
    int k = t % 26;
    if (k) {
      tmp = char('A' + k - 1) + tmp;
      t /= 26;
    } else {
      tmp = 'Z' + tmp;
      t = (t - 26) / 26;
    }
  }
  ans += tmp;
  tmp = "";
  t = x;
  while (t) {
    int k = t % 10;
    tmp = char('0' + k) + tmp;
    t /= 10;
  }
  ans += tmp;
  cout << ans << endl;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s);
    int type = gettype();
    if (type == 1)
      work1();
    else
      work2();
    if (type == 1)
      write2();
    else
      write1();
  }
  return 0;
}
