#include <bits/stdc++.h>
using namespace std;
int do_it1(string s) {
  int ans = 0;
  for (int i = 0; i < s.length(); i++) {
    ans = ans * 26 + (s[i] - 'A' + 1);
  }
  return ans;
}
string do_it2(int a) {
  string s = "";
  while (a != 0) {
    s += ('A' + ((a - 1) % 26));
    a = (a - 1) / 26;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  string s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    bool ok1 = false;
    bool ok2 = false;
    for (int i = 0; i < s.length(); i++)
      if (isdigit(s[i]))
        if (ok1 == true)
          ok2 = true;
        else {
          ok1 = true;
          while (isdigit(s[i])) ++i;
        }
    if (ok1 && ok2) {
      int i = 1;
      int c1 = 0, c2 = 0;
      while (isdigit(s[i])) {
        c1 = c1 * 10 + s[i] - '0';
        ++i;
      }
      ++i;
      while (isdigit(s[i])) {
        c2 = c2 * 10 + s[i] - '0';
        ++i;
      }
      cout << do_it2(c2) << c1 << endl;
    } else {
      string temp = "", temp2 = "";
      for (int i = 0; i < s.length(); i++)
        if (isalpha(s[i]))
          temp += s[i];
        else
          temp2 += s[i];
      cout << 'R' << temp2 << 'C' << do_it1(temp) << endl;
    }
  }
}
