#include <bits/stdc++.h>
using namespace std;
void schimb(int j) {
  if (j) {
    schimb((j - 1) / 26);
    putchar('A' + (j - 1) % 26);
  }
}
int main() {
  int n, randu, coloana, i;
  char sheet[100], *a;
  scanf("%d", &n);
  while (n--) {
    cin >> sheet;
    if (sscanf(sheet, "R%dC%d", &randu, &coloana) == 2) {
      schimb(coloana);
      printf("%d\n", randu);
    } else {
      for (i = 0, a = sheet; *a >= 'A'; a++) i = i * 26 + *a - 64;
      printf("R%sC%d\n", a, i);
    }
  }
  return 0;
}
