#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
template <class T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i + 1 == v.size())
      out << v[i];
    else
      out << v[i] << " ";
  }
  return out;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ts;
  cin >> ts;
  while (ts--) {
    string s;
    cin >> s;
    bool first = false;
    int i = 0;
    while (s[i] >= 'A') i++;
    while (s[i] < 'A' && i != s.size()) i++;
    if (i == s.size())
      first = true;
    else
      first = false;
    if (first) {
      reverse(s.begin(), s.end());
      int c = 0;
      while (s.back() >= 'A') {
        c *= 26;
        c += s.back() - 'A' + 1;
        s.pop_back();
      }
      reverse(s.begin(), s.end());
      int r = stoi(s);
      cout << "R" << r << "C" << c << endl;
    } else {
      i = 1;
      string str;
      while (s[i] < 'A') {
        str.push_back(s[i]);
        i++;
      }
      int r = stoi(str);
      str = "";
      i++;
      while (i < s.size()) {
        str.push_back(s[i]);
        i++;
      }
      int c = stoi(str);
      str = "";
      while (c > 0) {
        c--;
        str.push_back('A' + c % 26);
        c /= 26;
      }
      reverse(str.begin(), str.end());
      cout << str << r << endl;
    }
  }
}
