#include <bits/stdc++.h>
using namespace std;
void to1(string a, string b) {
  a = 'R' + a + 'C';
  long long n = 0;
  for (long long i = 0; i < b.size(); i++) {
    n += pow(26, b.size() - 1 - i) * (b[i] - 'A' + 1);
  }
  cout << a << n << endl;
}
void to2(string a, string b) {
  long long n = 0;
  for (long long i = b.size() - 1; i >= 0; i--)
    n += pow(10, b.size() - 1 - i) * (b[i] - '0');
  b = "";
  while (n) {
    long long x = (--n) % 26;
    char i = x + 'A';
    b = i + b;
    n /= 26;
  }
  cout << b << a << endl;
}
void solve(long long ii) {
  string s;
  cin >> s;
  string a, b;
  long long t = 2;
  if (s[0] == 'R' and s[1] <= '9') {
    long long i = 1;
    while (i < s.size() and s[i] >= '0' and s[i] <= '9') i++;
    if (i != s.size()) t = 1;
  }
  if (t == 1) {
    for (long long i = 1; i < s.size() and s[i] != 'C'; i++) a += s[i];
    for (long long i = s.size() - 1; i > 0 and s[i] != 'C'; i--) b = s[i] + b;
    to2(a, b);
  } else {
    for (long long i = 0; i < s.size() and s[i] > '9'; i++) a += s[i];
    for (long long i = s.size() - 1; i > 0 and s[i] <= '9'; i--) b = s[i] + b;
    to1(b, a);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt, ii = 0;
  cin >> tt;
  while (ii++ < tt) solve(ii);
  cerr << "[Execution : " << (1.0 * clock()) / CLOCKS_PER_SEC << "s]\n";
  return 0;
}
