#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int T;
  string s;
  cin >> T;
  while (T--) {
    cin >> s;
    bool f = false;
    long long int p = 0;
    for (long long int i = 1; i < s.size(); i++) {
      if (s[i] >= 'A' && (s[i - 1] >= '0' && s[i - 1] <= '9')) {
        p = i;
        f = true;
        break;
      }
    }
    if (f) {
      long long int x = 0;
      for (long long int i = p + 1; i < s.size(); i++) {
        x = x * 10 + (s[i] - '0');
      }
      string t;
      while (x) {
        if (x % 26)
          t.push_back((char)('A' + (x % 26) - 1));
        else {
          t.push_back('Z');
          x--;
        }
        x /= 26;
      }
      for (long long int i = t.size() - 1; i >= 0; i--) cout << t[i];
      for (long long int i = 1; i < p; i++) cout << s[i];
      cout << "\n";
    } else {
      cout << 'R';
      for (long long int i = 0; i < s.size(); i++) {
        if (s[i] <= '9')
          cout << s[i];
        else
          p = i;
      }
      cout << 'C';
      long long int x = 0, k = 1;
      for (long long int i = p; i >= 0; i--) {
        x += k * (s[i] - 'A' + 1);
        k *= 26;
      }
      cout << x << "\n";
    }
  }
  return 0;
}
