#include <bits/stdc++.h>
using namespace std;
int n, q, row, col;
string s, t;
bool isL(char c) { return 'A' <= c && c <= 'Z'; }
bool isD(char c) { return '0' <= c && c <= '9'; }
string toLetters(int x) {
  string s = "";
  while (x > 0) {
    x--;
    s = (char)('A' + x % 26) + s;
    x = x / 26;
  }
  return s;
}
int toInteger(string s) {
  int w = s[s.length() - 1] - 'A' + 1;
  int q = 1;
  for (int i = s.length() - 2; i >= 0; i--) {
    q *= 26;
    w += (s[i] - 'A' + 1) * q;
  }
  if (q == 1) q = 0;
  return w;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s;
    q = 0;
    for (int j = 0; j < s.length() - 1; j++)
      if (isL(s[j]) && isD(s[j + 1])) q++;
    if (q == 2) {
      row = 0;
      col = 0;
      int j = 1;
      for (; j < s.length(); j++)
        if (isD(s[j]))
          row = row * 10 + (s[j] - '0');
        else
          break;
      j++;
      for (; j < s.length(); j++)
        if (isD(s[j]))
          col = col * 10 + (s[j] - '0');
        else
          break;
      cout << toLetters(col) << row;
    } else {
      row = 0;
      t = "";
      int j = 0;
      for (; j < s.length(); j++)
        if (isL(s[j]))
          t = t + s[j];
        else
          break;
      for (; j < s.length(); j++)
        if (isD(s[j]))
          row = row * 10 + (s[j] - '0');
        else
          break;
      cout << "R" << row << "C" << toInteger(t);
    }
    cout << endl;
  }
  return 0;
}
