#include <bits/stdc++.h>
using namespace std;
char s[20];
bool judge(char s[]) {
  int l = strlen(s);
  int ans = 0;
  for (int i = 1; i < l; i++)
    if ((s[i] >= '0' && s[i] <= '9') && (s[i - 1] >= 'A' && s[i - 1] <= 'Z'))
      ans++;
  if (ans == 2) return true;
  return false;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    if (judge(s)) {
      int l = strlen(s);
      int r = 0, c = 0;
      int rr = 1, cc = 1;
      int i, j;
      for (i = l - 1; i >= 0; i--) {
        if (s[i] >= 'A' && s[i] <= 'Z') break;
        if (s[i] >= '0' && s[i] <= '9') {
          c += cc * (s[i] - '0');
          cc *= 10;
        }
      }
      for (j = i - 1; j >= 0; j--) {
        if (s[j] >= 'A' && s[j] <= 'Z') break;
        if (s[j] >= '0' && s[j] <= '9') {
          r += rr * (s[j] - '0');
          rr *= 10;
        }
      }
      stack<char> st;
      while (!st.empty()) st.pop();
      while (c) {
        int num = c % 26;
        if (num == 0) {
          st.push('Z');
          c--;
        } else
          st.push(num - 1 + 'A');
        c /= 26;
      }
      while (!st.empty()) {
        printf("%c", st.top());
        st.pop();
      }
      printf("%d\n", r);
    } else {
      int r = 0, c = 0;
      int rr = 1, cc = 1;
      int i, j, l = strlen(s);
      stack<char> st;
      stack<char> nt;
      while (!nt.empty()) nt.pop();
      while (!st.empty()) st.pop();
      for (i = 0; i < l; i++) {
        if (s[i] >= '0' && s[i] <= '9') break;
        st.push(s[i]);
      }
      for (j = i; j < l; j++) {
        nt.push(s[j]);
      }
      while (!st.empty()) {
        c += cc * (st.top() - 'A' + 1);
        cc *= 26;
        st.pop();
      }
      while (!nt.empty()) {
        r += rr * (nt.top() - '0');
        rr *= 10;
        nt.pop();
      }
      printf("R%dC%d\n", r, c);
    }
  }
  return 0;
}
