#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str, r, c;
    cin >> str;
    int flag = 0;
    for (int i = 1; i < str.size(); i++) {
      if (str[i] == 'C' && str[i - 1] < 'A') {
        flag = 1;
        break;
      }
    }
    if (flag) {
      int i = 1;
      for (; str[i] < 'A'; i++) {
        r += str[i];
      }
      for (i++; i < str.size(); i++) {
        c += str[i];
      }
      int cc = atoi(c.c_str());
      string ct;
      while (cc > 0) {
        if (cc % 26 == 0) {
          ct += 'Z';
          cc /= 26;
          cc -= 1;
        } else {
          ct += cc % 26 + 'A' - 1;
          cc /= 26;
        }
      }
      for (i = ct.size() - 1; i >= 0; i--) {
        cout << ct[i];
      }
      cout << r << endl;
    } else {
      int i = 0;
      for (; str[i] >= 'A'; i++) {
        c += str[i];
      }
      for (i; i < str.size(); i++) {
        r += str[i];
      }
      int cc = 0;
      for (i = 0; i < c.size(); i++) {
        cc += (int)1 * (c[i] - 'A' + 1) * pow(26, c.size() - 1 - i);
      }
      cout << "R" << r << "C" << cc << endl;
    }
  }
  return 0;
}
