#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int to_n(string x) {
  int ans = 0;
  for (int i = 0; i < x.size(); i++) {
    ans *= 10;
    ans += (x[i] - '0');
  }
  return ans;
}
void func(int n) {
  while (n) {
    if (n % 26)
      v.push_back(n % 26);
    else {
      v.push_back(26);
      n -= 26;
    }
    n /= 26;
  }
}
int inv_func(string x) {
  int ans = 0;
  for (int i = 0; i < x.size(); i++) {
    ans *= 26;
    ans += (x[i] - 'A' + 1);
  }
  return ans;
}
void solve() {
  int n, m, i = 0;
  string s;
  cin >> s;
  string a = "", b = "", c = "", d = "";
  while (s[i] >= 'A' && s[i] <= 'Z' && i < s.size()) {
    a.push_back(s[i]);
    i++;
  }
  while (i < s.size() && s[i] >= '0' && s[i] <= '9') {
    b.push_back(s[i]);
    i++;
  }
  while (i < s.size() && s[i] >= 'A' && s[i] <= 'Z') {
    c.push_back(s[i]);
    i++;
  }
  while (i < s.size() && s[i] >= '0' && s[i] <= '9') {
    d.push_back(s[i]);
    i++;
  }
  if (c.size() > 0) {
    m = to_n(d);
    func(m);
    for (i = v.size() - 1; i >= 0; i--) cout << char(v[i] + 'A' - 1);
    cout << b;
    cout << endl;
    v.clear();
    return;
  }
  n = inv_func(a);
  cout << "R" << b << "C" << n << endl;
  v.clear();
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) solve();
}
