#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
bool prime(int n) {
  if (n == 0 || n == 1) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
void l1(int a, int b) {
  string t = "";
  int l = b;
  while (l) {
    int p = (l - 1) % 26;
    t += (char)(p + 'A');
    l = (l - 1) / 26;
  }
  reverse(t.begin(), t.end());
  cout << t;
  cout << a << endl;
}
void l2(char s[]) {
  int x;
  char *p;
  for (x = 0, p = s; *p > 64; ++p) x = x * 26 + *p - 64;
  printf("R%sC%d\n", p, x);
}
int main() {
  int t;
  cin >> t;
  for (scanf("%d", &t); t--;) {
    char s[64];
    gets(s);
    int x, y;
    if (sscanf(s, "%*c%d%*c%d", &x, &y) == 2) {
      l1(x, y);
    } else {
      l2(s);
    }
  }
  return 0;
}
