#include <bits/stdc++.h>
using namespace std;
char a[27] = {'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
              'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
              'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int b[100];
char ch[100];
int main() {
  int t, k, sum, num;
  scanf("%d", &t);
  while (t--) {
    cin >> ch;
    sum = 0, num = 0;
    bool flag = true;
    int n = strlen(ch);
    if (ch[0] == 'R' && ch[1] >= '0' && ch[1] <= '9') {
      for (int i = 2; i < n; i++)
        if (ch[i] == 'C') flag = false;
    }
    if (flag) {
      for (int i = 0; i < n; i++)
        if (ch[i] >= '0' && ch[i] <= '9') {
          k = i;
          break;
        }
      for (int i = k - 1, j = 0; i >= 0; i--, j++)
        sum += (int)(ch[i] - 'A' + 1) * pow(26.0, j);
      for (int i = n - 1, j = 0; i >= k; i--, j++)
        num += (int)(ch[i] - '0') * pow(10.0, j);
      printf("R%dC%d\n", num, sum);
    }
    if (!flag) {
      for (int i = 1; i < n; i++)
        if (ch[i] == 'C') {
          k = i;
          break;
        }
      for (int i = k - 1, j = 0; i >= 1; i--, j++)
        sum += (int)(ch[i] - '0') * pow(10.0, j);
      for (int i = n - 1, j = 0; i > k; i--, j++)
        num += (int)(ch[i] - '0') * pow(10.0, j);
      for (int i = 0; num;) {
        int tem = num % 26;
        b[i++] = tem;
        if (num % 26 == 0)
          num = num / 26 - 1;
        else
          num = num / 26;
        k = i;
      }
      for (int i = k - 1; i >= 0; i--) printf("%c", a[b[i]]);
      printf("%d\n", sum);
    }
  }
  return 0;
}
