#include <bits/stdc++.h>
using namespace std;
int ALtoR(char s[15]) { return 0; }
int isRC(char s[15]) {
  int ik, r;
  ik = 1;
  r = 0;
  if (s[0] == 'R') {
    while (s[ik] != 0) {
      if ((s[ik] == 'C') && (s[ik - 1] <= '9')) {
        r = 1;
        break;
      }
      ik++;
    }
  }
  return r;
}
int printAL(char s[15]) {
  int ih;
  long k;
  ih = 0;
  k = 0;
  cout << 'R';
  while (s[ih] > '9') {
    k = k * 26 + s[ih] - 64;
    ih++;
  }
  while (s[ih] > 0) {
    cout << s[ih];
    ih++;
  }
  cout << 'C' << k;
  cout << endl;
  return 0;
}
int printRC(char s[15]) {
  int il;
  long k;
  il = 1;
  k = 0;
  while (s[il] != 'C') {
    il++;
  }
  il++;
  while ((s[il] <= '9') && (s[il] > 0)) {
    k = k * 10 + s[il] - 48;
    il++;
  }
  char l[6];
  il = 0;
  while (k > 26) {
    if (k % 26 > 0) {
      l[il] = k % 26 + 64;
      k = k / 26;
    } else {
      l[il] = 'Z';
      k = k / 26 - 1;
    }
    il++;
  }
  if (k % 26 > 0) {
    l[il] = k % 26 + 64;
  } else {
    l[il] = 'Z';
  }
  il++;
  int is = 0;
  while (is < il) {
    cout << l[il - is - 1];
    is++;
  }
  il = 1;
  while (s[il] != 'C') {
    cout << s[il];
    il++;
  }
  cout << endl;
  return 0;
}
int main() {
  int n, i;
  char s[15];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (isRC(s) == 0) {
      printAL(s);
    } else {
      printRC(s);
    }
  }
  return 0;
}
