#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T const& Max(T const& a, T const& b) {
  return a > b ? a : b;
}
template <typename T>
T const& Min(T const& a, T const& b) {
  return a < b ? a : b;
}
template <typename T>
inline T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}
template <typename T>
T sqaa(T a) {
  return a * a;
}
int main() {
  ios_base ::sync_with_stdio(false);
  int n, i;
  string second[100005];
  string alp = "ZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  while (cin >> n) {
    for (int i = (0); i < (n); i++) cin >> second[i];
    for (int i = (0); i < (n); i++) {
      if (second[i][0] == 'R' && isdigit(second[i][1]) &&
          second[i].find('C') != string ::npos) {
        int c = second[i].find('C');
        string row = second[i].substr(1, c - 1);
        string col = second[i].substr(c + 1);
        string ans = "";
        int column = atoi(col.c_str());
        while (column > 26) {
          int j = column / 26;
          int k = column % 26;
          ans = alp[k] + ans;
          if (!k) j--;
          column = j;
        }
        ans = alp[column] + ans;
        cout << ans << row << "\n";
      } else {
        string row = "";
        int j;
        for (j = second[i].size() - 1; !isalpha(second[i][j]); j--)
          row = second[i][j] + row;
        string col = second[i].substr(0, j + 1);
        int tot;
        tot = col[0] - 'A' + 1;
        if (col.size() > 1) {
          tot *= 26;
          tot += (col[1] - 'A' + 1);
        }
        for (j = 2; j < (int)(col).size(); j++) {
          tot *= 26;
          tot += col[j] - 'A' + 1;
        }
        cout << 'R' << row << 'C' << tot << "\n";
      }
    }
  }
  return 0;
}
