#include <bits/stdc++.h>
using namespace std;
char s[16], s0[6];
int main() {
  int n, l, x, a, b, c;
  scanf("%d", &n);
  while (n--) {
    x = b = 0;
    a = 0;
    scanf("%s", s);
    l = strlen(s);
    while (s[x] > 64) a = 26 * a + s[x++] - 64;
    while (x < l && s[x] < 65) b = 10 * b + s[x++] - 48;
    if (x == l) {
      printf("R%dC%d\n", b, a);
      continue;
    }
    c = 0;
    ++x;
    while (x < l && s[x] < 65) c = 10 * c + s[x++] - 48;
    x = 0;
    while (c) {
      --c;
      s0[x++] = c % 26 + 65;
      c /= 26;
    }
    for (int i = x - 1; ~i; --i) printf("%c", s0[i]);
    printf("%d\n", b);
  }
}
