#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  string s;
  string st;
  long long a;
  long long b;
  long long temp;
  long pos;
  bool flag = false;
  for (long i = 0; i < n; i++) {
    cin >> s;
    st.clear();
    flag = false;
    for (long i = 1; i < s.size(); i++)
      if ((s[i - 1] >= '0' && s[i - 1] <= '9') && !(s[i] >= '0' && s[i] <= '9'))
        flag = true;
    if (flag == false) {
      pos = 0;
      while (!(s[pos] >= '0' && s[pos] <= '9')) pos++;
      pos--;
      temp = 1;
      a = 0;
      for (long i = pos; i >= 0; i--) {
        a += temp * (s[i] - 'A' + 1);
        temp *= 26;
      }
      temp = 1;
      b = 0;
      for (long i = s.size() - 1; i > pos; i--) {
        b += temp * (s[i] - '0');
        temp *= 10;
      }
      cout << "R" << b << "C" << a << "\n";
    } else {
      pos = 0;
      while (s[pos] != 'C') pos++;
      pos--;
      temp = 1;
      a = 0;
      for (long i = pos; i >= 1; i--) {
        a += temp * (s[i] - '0');
        temp *= 10;
      }
      temp = 1;
      b = 0;
      for (long i = s.size() - 1; i > pos + 1; i--) {
        b += temp * (s[i] - '0');
        temp *= 10;
      }
      while (b != 0) {
        st.push_back(b % 26 + 'A' - 1);
        b /= 26;
      }
      reverse(st.begin(), st.end());
      for (long i = st.size() - 1; i >= 1; i--)
        if (st[i] <= '@') {
          st[i - 1]--;
          st[i] += 26;
        }
      while (st[0] == '@') st.erase(0, 1);
      cout << st << a << "\n";
    }
  }
}
