#include <bits/stdc++.h>
int type(char *str, int len) {
  if (str[0] == 'R' && str[1] <= '9' && str[1] >= '0') {
    int i;
    for (i = 2; i < len; i++)
      if (str[i] == 'C') return 1;
  }
  return 2;
}
int toNumber(char *str, int len) {
  int i, n;
  for (i = 0, n = 0; i < len; i++) n = n * 26 + (str[i] - 'A' + 1);
  return n;
}
void convertToRC(char *str, int len) {
  char *prow;
  int col_len;
  for (prow = str, col_len = 0; *prow <= 'Z' && *prow >= 'A'; prow++, col_len++)
    ;
  printf("R%sC%d\n", prow, toNumber(str, col_len));
}
void toLetter(char *str, int len) {
  char ch[16 / 2];
  int i, n;
  for (i = 0, n = atoi(str); n > 0; i++) {
    if (n % 26 == 0) {
      ch[i] = 'Z';
      n = n / 26 - 1;
    } else {
      ch[i] = 'A' + n % 26 - 1;
      n = n / 26;
    }
  }
  for (i = i - 1; i > -1; i--) printf("%c", ch[i]);
}
void convertToCR(char *str, int len) {
  char *pcol;
  int row_len;
  for (pcol = &str[1], row_len = 0; *pcol <= '9' && *pcol >= '0';
       pcol++, row_len++)
    ;
  toLetter(pcol + 1, len - 2 - row_len);
  int i;
  for (i = 1; i <= row_len; i++) printf("%c", str[i]);
  printf("\n");
}
void convert(char *str, int len) {
  int t;
  t = type(str, len);
  if (t == 1)
    convertToCR(str, len);
  else if (t == 2)
    convertToRC(str, len);
}
int main() {
  int i, n;
  scanf("%d", &n);
  char in[16];
  for (i = 0; i < n; i++) {
    scanf("%s", in);
    convert(in, strlen(in));
  }
  return 0;
}
