#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkMin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkMax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Myabs(T a) {
  return a > 0 ? a : -a;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int inf = 0x3f3f3f3f;
const long long linf = 1LL << 60;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int mod = 100000007;
const int maxn = 10010;
int n, r, c;
char ch[maxn], s[maxn];
void print(int v) {
  if (v) {
    print((v - 1) / 26);
    printf("%c", 'A' + (v - 1) % 26);
  }
}
int main() {
  scanf("%d", &n);
  for (int cas = 1; cas <= n; cas++) {
    scanf("%s", ch);
    if (sscanf(ch, "R%dC%d", &r, &c) == 2) {
      print(c);
      printf("%d\n", r);
    } else {
      sscanf(ch, "%[^0-9]%d", s, &r);
      int ans = 0;
      for (int i = 0; s[i]; i++) ans *= 26, ans += s[i] - 'A' + 1;
      printf("R%dC%d\n", r, ans);
    }
  }
  return 0;
}
