#include <bits/stdc++.h>
char a[100], b[100];
void turn(int x) {
  if (x) {
    turn((x - 1) / 26);
    printf("%c", 'A' + (x - 1) % 26);
  }
}
int main() {
  int t, i, j, n, m;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", a);
    if (sscanf(a, "%*c%d%*c%d", &n, &m) == 2) {
      turn(m);
      printf("%d\n", n);
    } else {
      strcpy(b, a);
      int len;
      n = i = 0;
      len = strlen(b);
      while (b[i] >= 'A') {
        n = n * 26 + b[i] - 'A' + 1;
        i++;
      }
      printf("R");
      for (int j = i; j < len; j++) printf("%c", b[j]);
      printf("C%d\n", n);
    }
  }
  return 0;
}
