#include <bits/stdc++.h>
using namespace std;
int N, i, j, a, b;
string S, T;
char C;
bool cek;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  while (N--) {
    cin >> S;
    for (i = 0; S[i] >= 'A' && S[i] <= 'Z'; i++) {
    }
    for (j = i; S[j] >= '0' && S[j] <= '9'; j++) {
    }
    if (j == S.length())
      cek = 1;
    else
      cek = 0;
    if (cek) {
      a = 0, j = 0, i = 0;
      for (i = 0; S[i] >= 'A' && S[i] <= 'Z'; i++) {
      }
      cout << 'R';
      for (j = i; j < S.length(); j++) cout << S[j];
      i--;
      for (j = 0; i >= 0; i--) {
        a += (S[i] - 'A' + 1) * pow(26, j);
        j++;
      }
      cout << 'C' << a << '\n';
    } else {
      b = 0, j = 0, i = 0;
      T = "";
      for (j = S.length() - 1; S[j] >= '0' && S[j] <= '9'; j--) {
      }
      for (i = j + 1; i < S.length(); i++) b = b * 10 + (S[i] - '0');
      while (b > 0) {
        T = (char)((b - 1) % 26 + 'A') + T;
        b = (b - (b - 1) % 26 - 1) / 26;
      }
      cout << T;
      for (j = 1; S[j] >= '0' && S[j] <= '9'; j++) cout << S[j];
      cout << '\n';
    }
  }
}
