#include <bits/stdc++.h>
using namespace std;
int pow(int a, int b) {
  int i, k;
  k = 1;
  for (i = 1; i <= b; i++) k = k * a;
  return k;
}
void chuyen1(string s) {
  int R, C, i, d1, temp;
  char c;
  string s3 = "";
  R = s.find('R');
  C = s.find('C');
  temp = 0;
  for (i = C + 1; i <= s.length() - 1; i++) temp = temp * 10 + (s[i] - 48);
  while (temp > 0) {
    if ((temp % 26) != 0) {
      d1 = temp % 26 + 64;
      c = (char)(d1);
      s3 = c + s3;
      temp = temp / 26;
    } else {
      d1 = 26 + 64;
      c = (char)(d1);
      s3 = c + s3;
      temp = temp / 26 - 1;
    }
  }
  cout << s3;
  for (i = 1; i < C; i++) cout << s[i];
  cout << "\n";
}
void chuyen2(string s) {
  int temp, i, k, j, tam;
  i = 0;
  while (s[i] >= 65 && s[i] <= 90) i++;
  k = i - 1;
  tam = k;
  temp = 0;
  for (j = 0; j <= k; j++) {
    temp = temp + (s[j] - 64) * pow(26, tam);
    tam--;
  }
  cout << 'R';
  for (j = i; j <= s.length() - 1; j++) cout << s[j];
  cout << 'C';
  cout << temp;
  cout << "\n";
}
int main() {
  int n, i;
  string s;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    if ((s[0] == 'R') && (s[1] >= '0') && (s[1] <= '9') &&
        (s.find('C', 2) >= 0) && (s.find('C', 2) <= s.length()))
      chuyen1(s);
    else
      chuyen2(s);
  }
}
