#include <bits/stdc++.h>
using namespace std;
string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
long long int toInt(string s) {
  long long int x = 0;
  for (long long int i = 0; i < s.size(); i++) {
    x += (s[i] - '0') * (long long int)pow(10, s.size() - i - 1);
  }
  return x;
}
string toChars(long long int x) {
  string s = "";
  while (x) {
    x--;
    s = (char)((x) % 26 + 'A') + s;
    x /= 26;
  }
  return s;
}
long long int backChars(string s) {
  long long int x = 0;
  for (long long int i = 0; i < s.size(); i++) {
    x += ((s[i] - 'A') + 1) * (long long int)pow(26, s.size() - i - 1);
  }
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    string s = "";
    bool f = 0;
    cin >> s;
    for (long long int i = 0; i < s.size(); i++)
      if (i - 1 > 0 && s[i] == 'C' && isdigit(s[i - 1])) f = 1;
    if (f) {
      string sn1 = "", sn2 = "";
      bool rc = 1;
      for (long long int i = 0; i < s.size(); i++) {
        if (s[i] == 'C') rc = 0;
        if (s[i] == 'C' || s[i] == 'R') continue;
        if (rc)
          sn1 += s[i];
        else
          sn2 += s[i];
      }
      long long int n2 = toInt(sn2);
      cout << toChars(n2) << sn1;
    } else {
      string sc = "", sn = "";
      bool rc = 1;
      for (long long int i = 0; i < s.size(); i++) {
        if (isdigit(s[i])) rc = 0;
        if (rc)
          sc += s[i];
        else
          sn += s[i];
      }
      cout << 'R' << sn << 'C' << backChars(sc);
    }
    cout << '\n';
  }
}
