#include <bits/stdc++.h>
using namespace std;
char s[64];
void g(int t) {
  if (t) {
    g((t - 1) / 26);
    putchar(65 + (t - 1) % 26);
  }
}
int main() {
  int x, y, n;
  char *p;
  for (scanf("%d ", &n); n--;) {
    gets(s);
    if (sscanf(s, "%*c%d%*c%d", &x, &y) == 2) {
      g(y);
      cout << x << endl;
    } else {
      for (x = 0, p = s; *p > 64; ++p) x = x * 26 + *p - 64;
      cout << "R" << p << "C" << x << endl;
    }
  }
  return 0;
}
