#include <bits/stdc++.h>
using namespace std;
char s[100005];
int t, n, shu[100005];
void solve(int cur) {
  int len = 0;
  while (cur) {
    shu[++len] = (cur - 1) % 26;
    cur = (cur - 1) / 26;
  }
  for (int i = len; i >= 1; i--) printf("%c", (char)('A' + shu[i]));
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    int type = 1;
    for (int i = 2; i <= n; i++)
      if (s[i - 1] <= '9' && s[i - 1] >= '0' && s[i] <= 'Z' && s[i] >= 'A')
        type = 0;
    if (!type) {
      int val = 0;
      for (int i = n, j = 1; s[i] >= '0' && s[i] <= '9'; i--, j *= 10)
        val += (s[i] - '0') * j;
      solve(val);
      for (int i = 2; s[i] >= '0' && s[i] <= '9'; i++) printf("%c", s[i]);
      printf("\n");
    } else {
      int i, row = 0, j, column = 0;
      for (i = n, j = 1; s[i] >= '0' && s[i] <= '9'; i--, j *= 10)
        row += (s[i] - '0') * j;
      for (j = 1; i >= 1; i--, j *= 26) column += (s[i] - 'A' + 1) * j;
      printf("R%dC%d\n", row, column);
    }
  }
}
