#include <bits/stdc++.h>
using namespace std;
int n;
char s[1000];
bool check_type() {
  int i;
  for (i = 1; s[i]; i++) {
    if (!isdigit(s[i]) && isdigit(s[i - 1])) return true;
  }
  return false;
}
void first() {
  int i, n = 0, m = 0;
  for (i = 0; !isdigit(s[i]); i++) n = 26 * n + s[i] - 'A' + 1;
  for (; s[i]; i++) m = 10 * m + s[i] - '0';
  cout << "R" << m << "C" << n << endl;
}
void second() {
  int i, j, n = 0, m = 0, z = 0;
  for (i = 1; isdigit(s[i]); i++) n = 10 * n + s[i] - '0';
  for (++i; s[i]; i++) m = 10 * m + s[i] - '0';
  while (m) {
    s[z++] = m % 26 + 'A' - 1;
    if (s[z - 1] < 'A') {
      s[z - 1] = 'Z';
      m -= 26;
    }
    m /= 26;
  }
  for (j = z - 1; j >= 0; j--) cout << s[j];
  cout << n << endl;
}
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%s", &s);
    check_type();
    if (!check_type())
      first();
    else
      second();
  }
  return 0;
}
