#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char s[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    bool f = 1;
    int cnt = 0;
    for (int i = 0; s[i]; i++) {
      if (f && isdigit(s[i])) f = 0;
      if (!f && isalpha(s[i])) {
        f = 1;
        cnt++;
      }
    }
    if (cnt == 0) {
      int x = 0, y = 0;
      for (int i = 0; s[i]; i++) {
        if (isalpha(s[i]))
          x = x * 26 + s[i] - 'A' + 1;
        else {
          y = i;
          break;
        }
      }
      cout << 'R' << s + y << 'C' << x << endl;
    } else {
      bool f = 0;
      int x = 0;
      for (int i = 1; s[i]; i++) {
        if (f) x = x * 10 + s[i] - '0';
        if (isalpha(s[i])) {
          s[i] = 0;
          f = 1;
        }
      }
      stack<char> stk;
      while (x) {
        int t = 'A' + (x - 1) % 26;
        stk.push('A' + (x - 1) % 26);
        x -= (x - 1) % 26 + 1;
        x /= 26;
      }
      while (!stk.empty()) {
        char c = stk.top();
        cout << c;
        stk.pop();
      }
      cout << s + 1 << endl;
    }
  }
}
