#include <bits/stdc++.h>
int classify(char code[]) {
  if (code[0] != 'R' || (code[0] == 'R' && code[1] == 'C'))
    return 1;
  else {
    int cnt = 0;
    for (int i = 2; i < strlen(code) && cnt <= 1; i++) {
      if (code[i] == 'C' && code[i - 1] < 65) cnt++;
    }
    if (cnt != 1)
      return 1;
    else
      return 2;
  }
}
void convert(char code[], int c) {
  if (c == 1) {
    int row = 0, col = 0;
    for (int i = 0; i < strlen(code); i++) {
      if (code[i] > 64) {
        col *= 26;
        col += code[i] - 64;
      } else {
        row *= 10;
        row += code[i] - '0';
      }
    }
    printf("R%dC%d\n", row, col);
  } else if (c == 2) {
    int row = 0, col = 0;
    char cols[15];
    int i = 1;
    for (; code[i] != 'C'; i++) {
      row *= 10;
      row += code[i] - '0';
    }
    while (code[++i] != '\0') {
      col *= 10;
      col += code[i] - '0';
    }
    int k = 0;
    for (i = 1; i <= 456976; i *= 26) {
      if (col >= i) {
        col -= i;
      } else
        break;
    }
    i /= 26;
    for (; i > 0; i /= 26) {
      cols[k++] = 65 + col / i;
      col = col % i;
    }
    cols[k] = '\0';
    printf("%s%d\n", cols, row);
  }
}
int main() {
  int n, ctr = 0;
  char str[20];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    convert(str, classify(str));
  }
}
