#include <bits/stdc++.h>
using namespace std;
bool judge(char *p) {
  p++;
  if ('A' <= *p && *p <= 'Z') return true;
  for (p++; *p != '\0'; p++)
    if ('A' <= *p && *p <= 'Z') return false;
  return true;
}
int main() {
  int n;
  char str[20];
  scanf("%d", &n);
  while (n--) {
    scanf("%s", str);
    int i, r = 0, c = 0;
    if (judge(str)) {
      for (i = 0; 'A' <= str[i] && str[i] <= 'Z'; i++)
        c = 26 * c + (str[i] - 'A' + 1);
      for (; str[i] != '\0'; i++) r = 10 * r + (str[i] - '0');
      printf("R%dC%d\n", r, c);
    } else {
      for (i = 1; '0' <= str[i] && str[i] <= '9'; i++)
        r = 10 * r + (str[i] - '0');
      for (i++; '0' <= str[i] && str[i] <= '9'; i++)
        c = 10 * c + (str[i] - '0');
      int k = 0;
      char ans[10];
      while (c) {
        if (c % 26 != 0) {
          ans[k++] = 'A' + c % 26 - 1;
          c /= 26;
        } else {
          ans[k++] = 'Z';
          c = c / 26 - 1;
        }
      }
      ans[k] = '\0';
      reverse(ans, ans + k);
      printf("%s%d\n", ans, r);
    }
  }
  return 0;
}
