#include <bits/stdc++.h>
char a[1000005], tem[1000005];
void putout(long c);
int main() {
  long n, i, r, c;
  scanf("%ld", &n);
  while (n--) {
    scanf("%s", a);
    if (sscanf(a, "R%ldC%ld", &r, &c) == 2) {
      putout(c);
      printf("%ld\n", r);
    } else {
      sscanf(a, "%[A-Z]%ld", tem, &r);
      c = 0;
      for (i = 0; tem[i] != '\0'; i++) c = c * 26 + tem[i] - 'A' + 1;
      printf("R%ldC%ld\n", r, c);
    }
  }
  return 0;
}
void putout(long c) {
  if (c == 0)
    return;
  else
    putout((c - 1) / 26);
  printf("%c", (c - 1) % 26 + 'A');
}
