#include <bits/stdc++.h>
using namespace std;
int n, len, r, c;
char s[100], a[100];
void sol1() {
  int i, j;
  r = c = 0;
  for (j = len - 1; j > 0; j--)
    if (s[j] == 'C') break;
  for (i = 1; i < j; i++) r = 10 * r + int(s[i] - '0');
  for (j++; j < len; j++) c = 10 * c + int(s[j] - '0');
  memset(a, 0, sizeof(a));
  for (i = 0; c; i++) {
    if (c % 26) {
      a[i] = c % 26 - 1;
      c /= 26;
    } else {
      a[i] = 25;
      c = c / 26 - 1;
    }
  }
  for (i--; i >= 0; i--) printf("%c", char(a[i] + 'A'));
  printf("%d\n", r);
}
void sol2() {
  int i, j;
  r = c = 0;
  for (i = 0; i < len; i++) {
    if (s[i] >= '0' && s[i] <= '9') break;
    r = r * 26 + int(s[i] - 'A' + 1);
  }
  for (j = len - 1; j > 0; j--)
    if (s[j] >= 'A' && s[j] <= 'Z') break;
  for (j++; j < len; j++) c = 10 * c + int(s[j] - '0');
  printf("R%dC%d\n", c, r);
}
int main() {
  int i, cnt;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    len = strlen(s);
    cnt = 0;
    for (i = 1; i < len; i++)
      if (s[i] >= '0' && s[i] <= '9' && s[i - 1] >= 'A' && s[i - 1] <= 'Z')
        cnt++;
    if (cnt == 2)
      sol1();
    else
      sol2();
  }
  return 0;
}
