#include <bits/stdc++.h>
using namespace std;
int T, len;
char s[200];
bool flag;
int t[200];
char date[28] = {'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'};
inline void work1() {
  register int i, hang = 0, lie = 0, w = 0;
  for (i = 1; isdigit(s[i]); ++i) hang = hang * 10 + s[i] - 48;
  for (i = i + 1; i < len; ++i) lie = lie * 10 + s[i] - 48;
  while (lie) t[++w] = lie % 26, lie = lie / 26 - !(lie % 26);
  while (w) putchar(date[t[w--]]);
  printf("%d\n", hang);
}
inline void work2() {
  register int i, lie = 0, hang = 0;
  for (i = 0; isupper(s[i]); ++i) lie = lie * 26 + s[i] - 'A' + 1;
  for (i; i < len; ++i) hang = hang * 10 + s[i] - 48;
  printf("R%dC%d\n", hang, lie);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s);
    len = strlen(s);
    flag = 0;
    for (register int i = 0; i < len && !flag; ++i)
      if (i && isdigit(s[i - 1]) && isupper(s[i])) flag = 1;
    if (flag)
      work1();
    else
      work2();
  }
  return 0;
}
