#include <bits/stdc++.h>
using namespace std;
template <typename T>
string NumberToString(T pNumber) {
  ostringstream oOStrStream;
  oOStrStream << pNumber;
  return oOStrStream.str();
}
bool check(string x) {
  if (int(x[1]) >= 48 && int(x[1]) <= 57) {
    for (int i = 2; i < x.length(); i++) {
      if (x[i] == 'C') {
        return true;
      }
    }
  }
  return false;
}
long long f1(string x) {
  string charr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string res = "";
  long long ii = pow(26, x.length() - 1);
  long long sonuc = 0;
  for (int j = 0; j < x.length(); j++) {
    for (int i = 0; i < charr.length(); i++) {
      if (x[j] == charr[i]) {
        sonuc += ii * (i + 1);
        break;
      }
    }
    ii = ii / 26;
  }
  return sonuc;
}
string f(int x) {
  string charr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string res = "";
  char temp;
  while (x != 0) {
    if (x % 26 != 0) {
      res += charr[x % 26 - 1];
      x /= 26;
    } else {
      res += "Z";
      x /= 26;
      x = x - 1;
    }
  }
  for (int i = 0; i < res.length() / 2; i++) {
    temp = res[i];
    res[i] = res[res.length() - 1 - i];
    res[res.length() - 1 - i] = temp;
  }
  return res;
}
int main() {
  int t;
  cin >> t;
  string a;
  string ret[t];
  string op;
  string sop;
  bool stop;
  bool stop2;
  int sayac = 0;
  string res;
  int k;
  int g;
  for (int i = 0; i < t; i++) {
    cin >> a;
    stop = true;
    stop2 = false;
    res = "";
    sop = "";
    op = "";
    k = 0;
    if (a[0] == 'R' && check(a)) {
      for (int j = 1; j < a.length(); j++) {
        if (stop2) {
          sop += a[j];
        }
        if (a[j] == 'C') {
          stop = false;
          stop2 = true;
        } else if (stop) {
          op += a[j];
        }
      }
      istringstream ss(sop);
      ss >> g;
      res += f(g);
      res += op;
    } else {
      res += "R";
      while (int(a[k]) < 48 || int(a[k]) > 57) {
        op += a[k];
        k++;
      }
      for (int h = k; h < a.length(); h++) {
        sop += a[h];
      }
      res += sop;
      res += "C";
      res += NumberToString(f1(op));
    }
    ret[i] = res;
  }
  for (int h = 0; h < t; h++) {
    cout << ret[h] << endl;
  }
  return 0;
}
