#include <bits/stdc++.h>
using namespace std;
const char *a = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char s[101];
void _1() {
  int i = 0, j = 0, num1 = 0, num2 = 0;
  int t[101];
  for (++i; isdigit(s[i]); ++i) (num2 *= 10) += s[i] - '0';
  for (++i; s[i]; ++i) (num1 *= 10) += s[i] - '0';
  for (; num1; num1 = num1 / 26 - !(num1 % 26))
    if (num1 % 26)
      t[++j] = num1 % 26;
    else
      t[++j] = 26;
  for (; j; --j) putchar(a[t[j]]);
  printf("%d\n", num2);
}
void _2() {
  int i = 0, num1 = 0, num2 = 0;
  for (; isupper(s[i]); ++i) (num2 *= 26) += s[i] - 'A' + 1;
  for (; s[i]; ++i) (num1 *= 10) += s[i] - '0';
  printf("R%dC%d\n", num1, num2);
}
int main() {
  int n;
  bool f;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    f = 0;
    for (int i = 0; s[i] && !f; ++i)
      if (i && isdigit(s[i - 1]) && isupper(s[i])) f = 1;
    if (f)
      _1();
    else
      _2();
  }
  return 0;
}
