#include <bits/stdc++.h>
int n, pathcnt;
char data[100], path[100];
void check1() {
  int i, cnt = 0, now = 1;
  for (i = 0; i < n; i++)
    if (data[i] == 'C') break;
  for (i++; i < n; i++) {
    cnt *= 10;
    cnt += data[i] - '0';
  }
  while (1) {
    if (now * 26 < cnt) {
      now *= 26;
      continue;
    }
    path[pathcnt++] = cnt / now + 'A' - 1;
    cnt = cnt % now;
    if (now == 1) break;
    if (cnt == 0) {
      path[pathcnt - 1]--;
      cnt = now;
    }
    now /= 26;
    if (path[pathcnt - 1] == '@') {
      for (i = pathcnt - 1; i > 0; i--) {
        path[i] = 'Z';
        path[i - 1]--;
        if (path[i - 1] != '@') break;
      }
      if (path[0] == '@') {
        for (i = 0; i < pathcnt; i++) path[i] = path[i + 1];
        pathcnt--;
      }
    }
  }
  for (i = 0; i < n; i++)
    if (data[i] == 'C') break;
  data[i] = 0;
  printf("%s%s\n", path, data + 1);
}
void check2() {
  int i, now = 1, cnt = 0, t;
  for (i = 0; i < n; i++)
    if (!(data[i] >= 'A' && data[i] <= 'Z')) break;
  t = i;
  for (i--; i >= 0; i--) {
    cnt += now * (data[i] - 'A' + 1);
    now *= 26;
  }
  printf("R%sC%d\n", data + t, cnt);
}
void process() {
  int i;
  bool flag = false;
  if (data[0] == 'R' && !(data[1] >= 'A' && data[1] <= 'Z')) {
    for (i = 2; i < n; i++)
      if (data[i] >= 'A' && data[i] <= 'Z') break;
    if (i != n) flag = true;
  }
  if (flag == true)
    check1();
  else
    check2();
}
void input() {
  int i, m;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s", data);
    n = strlen(data);
    process();
    pathcnt = 0;
    memset(data, 0, sizeof(data));
    memset(path, 0, sizeof(path));
    n = 0;
  }
}
int main() {
  input();
  return 0;
}
