#include <bits/stdc++.h>
using namespace std;
string convert(int n) {
  --n;
  string result;
  for (; n >= 0; n = (n / 26) - 1) result += string(1, char(n % 26 + 'A'));
  reverse(result.begin(), result.end());
  return result;
}
int valueOf(string s) {
  int result = 0, i = 1;
  for (string::reverse_iterator it = s.rbegin(); it != s.rend(); ++it, i *= 26)
    result += ((*it) - 'A' + 1) * i;
  return result;
}
bool checkFormat(string s) {
  int i;
  for (i = 0; i < s.size(); ++i)
    if (!isalpha(s[i])) break;
  for (; i < s.size(); ++i)
    if (!isdigit(s[i])) break;
  return (i == s.size());
}
int main() {
  int n, i;
  string s;
  cin >> n;
  while (n--) {
    cin >> s;
    if (checkFormat(s)) {
      for (i = 0; i < s.size(); ++i)
        if (!isalpha(s[i])) break;
      string r, c;
      c = s.substr(0, i);
      r = s.substr(i);
      int val = valueOf(c);
      c = "";
      while (val) {
        c += (val % 10) + '0';
        val /= 10;
      }
      reverse(c.begin(), c.end());
      cout << "R" << r << "C" << c << endl;
    } else {
      for (i = 0; i < s.size(); ++i)
        if (s[i] == 'C') break;
      string r, c;
      r = s.substr(1, i - 1);
      c = s.substr(i + 1);
      int val = 0;
      for (int i = 0; i < c.size(); ++i) {
        val *= 10;
        val += (c[i] - '0');
      }
      c = convert(val);
      cout << c << r << endl;
    }
  }
  return 0;
}
