#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  int w = 1;
  char ch = 0;
  while (ch <= '0' || ch >= '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * w;
}
template <typename T>
inline void _write(T x) {
  if (x >= 10) _write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  _write(x);
}
inline int Real(int x) {
  if (x % 26)
    x = x / 26;
  else
    x = x / 26 - 1;
  return x;
}
inline void CHwrite(int x) {
  if (x > 26) CHwrite(Real(x));
  x = x % 26;
  if (x == 0) x = 26;
  putchar('A' + x - 1);
}
bool Check(string s) {
  for (int i = 1; i <= s.length() - 1; i++) {
    if (s[i] == 'C' && s[i - 1] >= '0' && s[i - 1] <= '9') return true;
  }
  return false;
}
int main() {
  int num;
  num = read();
  for (int i = 1; i <= num; i++) {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] >= '0' && s[1] <= '9' && Check(s)) {
      int x = 0, site = 0;
      for (int l = 1; l <= s.length() - 1; l++) {
        if (s[l] == 'C') {
          site = l + 1;
          break;
        }
        x = (x << 1) + (x << 3) + s[l] - '0';
      }
      int y = 0;
      for (int l = site; l <= s.length() - 1; l++)
        y = (y << 1) + (y << 3) + s[l] - '0';
      CHwrite(y), write(x);
      putchar('\n');
    } else {
      int x = 0, site = 0;
      for (int l = 0; l <= s.length() - 1; l++) {
        if (s[l] >= 'A' && s[l] <= 'Z')
          x = x * 26 + s[l] - 'A' + 1;
        else {
          site = l;
          break;
        }
      }
      int y = 0;
      for (int l = site; l <= s.length() - 1; l++)
        y = (y << 1) + (y << 3) + s[l] - '0';
      putchar('R');
      write(y);
      putchar('C');
      write(x);
      putchar('\n');
    }
  }
  return 0;
}
