#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int dem = 0, n = s.length(), r = 0, flag = 0;
    for (int i = 0; i < n; i++) {
      if (dem == 1 && s[i] == 'C') {
        r = i + 1;
        flag = 1;
        break;
      }
      if (dem == 0 && s[i] < 58) {
        dem++;
        r = i;
      }
    }
    if (flag) {
      int h = 0;
      for (int i = r; i < n; i++) h = h * 10 + (s[i] - '0');
      string ans = "";
      while (h != 0) {
        if (h % 26 == 0)
          ans = 'Z' + ans, h -= 26;
        else
          ans = char((h % 26) - 1 + 'A') + ans, h -= h % 26;
        h /= 26;
      }
      cout << ans;
      for (int i = 1; i < r - 1; i++) cout << s[i];
      cout << "\n";
    } else {
      int a = 0, dem = 1;
      for (int i = r - 1; i >= 0; i--) {
        a += (s[i] - 'A' + 1) * pow(26, (r - i - 1));
      }
      cout << "R";
      for (int i = r; i < n; i++) cout << s[i];
      cout << "C" << a << "\n";
    }
  }
}
