#include <bits/stdc++.h>
using namespace std;
int n, i;
string s;
char h[] = {'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'};
string itos(int n) {
  string s;
  while (n > 0) {
    s = char(n % 10 + '0') + s;
    n /= 10;
  }
  return s;
}
bool isrc(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C' && isdigit(s[i - 1]) && isdigit(s[i + 1])) return 1;
  }
  return 0;
}
string f(string s) {
  if (isrc(s)) {
    int i, p = 0;
    string q;
    bool ok = 0;
    for (i = 1; i < s.size(); i++) {
      if (isdigit(s[i])) {
        if (ok)
          p = p * 10 + s[i] - '0';
        else
          q += s[i];
      } else {
        ok = 1;
      }
    }
    string x = "";
    while (p > 0) {
      x = h[p % 26] + x;
      if (p % 26 == 0)
        p /= 26, p--;
      else
        p /= 26;
    }
    x += q;
    return x;
  } else {
    string q, k;
    int i;
    for (i = 0; i < s.size(); i++) {
      if (isdigit(s[i])) {
        q += s[i];
      } else {
        k += s[i];
      }
    }
    int p = 0, l = k.size() - 1;
    for (i = 0; i < k.size(); i++) {
      if (k[i] != 'Z')
        p += (k[i] - 'A' + 1) * pow(26, l);
      else
        p += pow(26, l + 1);
      l--;
    }
    string x = "R";
    x += q;
    x += "C";
    x += itos(p);
    return x;
  }
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    cout << f(s) << endl;
  }
}
