#include <bits/stdc++.h>
using namespace std;
bool isDig(char x) { return (x >= '0' && x <= '9'); }
bool isAlpha(char x) { return (x >= 'A' && x <= 'Z'); }
bool isRC(string &s) {
  bool numFnd = false;
  for (int i = 0; i < s.size(); i++) {
    if (numFnd && isAlpha(s[i])) {
      return true;
    }
    if (isDig(s[i])) {
      numFnd = true;
    }
  }
  return false;
}
void convertRCtoAZ(string &s) {
  string row = "";
  long long x = 0;
  for (int i = 1; i < s.size(); i++) {
    if (isAlpha(s[i])) {
      x = i + 1;
      break;
    }
    row += s[i];
  }
  long long pow10 = 1, col = 0;
  for (long long int i = s.size() - 1; i >= x; i--) {
    col += (s[i] - '0') * pow10;
    pow10 *= 10;
  }
  string res = "";
  while (col > 0) {
    cerr << "col"
         << ": " << col << "\n";
    ;
    if (col % 26 == 0) {
      res += 'Z';
      col /= 26;
      col--;
    } else {
      res += 'A' + (col % 26) - 1;
      col /= 26;
    }
  }
  reverse((res).begin(), (res).end());
  cout << res;
  cout << row << "\n";
}
void convertAZtoRC(string &s) {
  string res = "";
  int x = 0;
  for (int i = 0; i < s.size(); i++) {
    if (isDig(s[i])) {
      res += 'R';
      for (int j = i; j < s.size(); j++) {
        res += s[j];
      }
      x = i - 1;
      break;
    }
  }
  long long col = 0;
  long long pow26 = 1;
  for (int i = x; i >= 0; i--) {
    col += (s[i] - 'A' + 1) * pow26;
    pow26 *= 26;
  }
  res += 'C';
  cout << res;
  cout << col;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    if (isRC(s)) {
      convertRCtoAZ(s);
    } else {
      convertAZtoRC(s);
    }
  }
}
