#include <bits/stdc++.h>
void printCol(int num) {
  if (num == -1)
    return;
  else
    printCol((num / 26) - 1);
  printf("%c", num % 26 + 'A');
}
int main() {
  int n, type;
  scanf("%d", &n);
  while (n--) {
    type = -1;
    int i = 1;
    char coords[100];
    scanf("%s", coords);
    while (coords[i]) {
      if ((coords[i - 1] <= 'Z') && (coords[i - 1] >= 'A') &&
          (coords[i] >= '0') && (coords[i] <= '9'))
        type++;
      i++;
    }
    if (type == 0) {
      i = 0;
      int r = 0, c = 0;
      while ((coords[i] <= 'Z') && (coords[i] >= 'A')) {
        c = 26 * c + coords[i] + 1 - 'A';
        i++;
      }
      while (coords[i]) {
        r = 10 * r + coords[i] - '0';
        i++;
      }
      printf("R%dC%d\n", r, c);
    } else {
      int r = 0, c = 0;
      i = 1;
      while ((coords[i] <= '9') && (coords[i] >= '0')) {
        r = 10 * r + coords[i] - '0';
        i++;
      }
      i++;
      while ((coords[i] <= '9') && (coords[i] >= '0')) {
        c = 10 * c + coords[i] - '0';
        i++;
      }
      printCol(c - 1);
      printf("%d\n", r);
    }
  }
  return 0;
}
