#include <bits/stdc++.h>
using namespace std;
void fromex(string s) {
  long long a = 0, b = 0;
  for (int i = 0; i < (int)s.size(); ++i) {
    if (isalpha(s[i]))
      a = a * 26 + (s[i] - 'A' + 1);
    else
      b = b * 10 + (s[i] - '0');
  }
  cout << "R" << b << "C" << a << endl;
}
void toex(string s) {
  long long a = 0, b = 0;
  bool x = true;
  for (int i = 1; i < (int)s.size(); ++i) {
    if (!x) {
      b = b * 10 + s[i] - '0';
    }
    if (s[i] == 'C') x = false;
    if (x) a = a * 10 + s[i] - '0';
  }
  string s2 = "";
  while (b != 0) {
    s2 = char('A' + ((b - 1) % 26)) + s2;
    b = (b - 1) / 26;
  }
  cout << s2 << a << endl;
}
int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    bool x = false;
    for (int ii = 1; ii < (int)s.size(); ++ii) {
      if (isdigit(s[ii - 1]) && isalpha(s[ii])) {
        x = true;
        break;
      }
    }
    if (x)
      toex(s);
    else
      fromex(s);
  }
  return 0;
}
