#include <bits/stdc++.h>
using namespace std;
char s[200005];
char letter[27];
int l;
void f1() {
  int row = 0, col = 0;
  int t[100005];
  int i = 1;
  for (i = 1; i < l; i++) {
    if (s[i] <= 'Z' && s[i] >= 'A') break;
    row = row * 10 + s[i] - '0';
  }
  for (int j = i + 1; j < l; j++) {
    if (s[j] >= '0' && s[j] <= '9') col = col * 10 + s[j] - '0';
  }
  int j = 0;
  while (col) {
    if (col % 26 != 0) {
      t[j] = col % 26;
      col /= 26;
      j++;
    } else {
      t[j] = 26;
      col = col / 26 - 1;
      j++;
    }
  }
  for (i = j - 1; i >= 0; i--) {
    printf("%c", letter[t[i]]);
  }
  printf("%d\n", row);
}
void f2() {
  int i;
  int row = 0;
  int col = 0;
  for (i = 0; i < l; i++) {
    if (s[i] >= '0' && s[i] <= '9') break;
    col = col * 26 + s[i] - 'A' + 1;
  }
  for (; i < l; i++) {
    row = row * 10 + s[i] - '0';
  }
  printf("R%dC%d\n", row, col);
}
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  letter[1] = 'A';
  for (int i = 2; i <= 26; i++) letter[i] = letter[i - 1] + 1;
  while (n--) {
    gets(s);
    l = strlen(s);
    int flag = 0;
    for (int i = 0; i < l; i++) {
      if (s[i] <= '9' && s[i] >= '0' && (s[i + 1] <= 'Z' && s[i + 1] >= 'A')) {
        flag = 1;
        break;
      }
    }
    if (flag)
      f1();
    else
      f2();
  }
  return 0;
}
