#include <bits/stdc++.h>
using namespace std;
string alBaseTointBase(string &s) {
  int ans = 0;
  for (auto &c : s) ans = ans * 26 + (c - 'A' + 1);
  return to_string(ans);
}
string intBaseToalBase(int x) {
  string ans = "";
  int r;
  while (x) {
    r = (x - 1) % 26;
    x = (x - 1) / 26;
    ans.push_back(char(r + 'A'));
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int main() {
  int t, x, y;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    x = 0;
    y = 1;
    while (s.back() <= '9') {
      x += y * (s.back() - '0');
      y *= 10;
      s.pop_back();
    }
    if (s.back() == 'C' && s.size() > 1 && s[s.size() - 2] <= '9') {
      s.pop_back();
      s.erase(s.begin());
      cout << intBaseToalBase(x) + s << "\n";
    } else {
      cout << "R" + to_string(x) + "C" + alBaseTointBase(s) << "\n";
    }
  }
  return 0;
}
