#include <bits/stdc++.h>
using namespace std;
int input() {
  int res = 0;
  char c = ' ';
  while (c < '0' && c != '-') c = getchar();
  while (c >= '0') res = res * 10 + (c - '0'), c = getchar();
  return res;
}
const int N = 1e5 + 1;
string to_str(int x) {
  string res;
  while (x) res += '0' + x % 10, x /= 10;
  reverse(res.begin(), res.end());
  return res;
}
string rc(string s) {
  int i = 0, x = 0, y = 0;
  for (; i < s.size(); ++i)
    if (s[i] >= '0' && s[i] <= '9')
      break;
    else
      y = y * 26 + s[i] - 'A' + 1;
  for (; i < s.size(); ++i) x = x * 10 + (s[i] - '0');
  return {'R' + to_str(x) + 'C' + to_str(y)};
}
string aa(string s) {
  int i = 1, x = 0, y = 0;
  for (; s[i] != 'C'; ++i) x = x * 10 + (s[i] - '0');
  for (++i; i < s.size(); ++i) y = y * 10 + (s[i] - '0');
  string r;
  while (y) r += 'A' + (y - 1) % 26, y = (y - 1) / 26;
  reverse(r.begin(), r.end());
  return r + to_str(x);
}
int main() {
  for (int i = input(); i; --i) {
    string s;
    cin >> s;
    bool f = false, RC = false;
    for (auto i : s) {
      if (i >= 'A' && i <= 'Z' && f)
        RC = true;
      else if (i >= '0' && i <= '9')
        f = true;
    }
    if (RC)
      cout << aa(s) << endl;
    else
      cout << rc(s) << endl;
  }
}
