#include <bits/stdc++.h>
using namespace std;
void label(int col) {
  if (col > 0) {
    if (col % 26 == 0) {
      label((col - 26) / 26);
      printf("Z");
    } else {
      label(col / 26);
      printf("%c", col % 26 + 'A' - 1);
    }
  }
}
int main() {
  bool type, digit, checker;
  char s[18];
  int n, len, row, col;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    len = strlen(s);
    type = false;
    digit = false;
    for (int j = 0; j < len; j++) {
      if (s[j] >= '0' && s[j] <= '9')
        digit = true;
      else if (digit && s[j] == 'C')
        type = true;
    }
    row = col = 0;
    if (type) {
      digit = false;
      checker = false;
      for (int j = 0; j < len; j++) {
        if (!checker && s[j] >= '0' && s[j] <= '9') {
          digit = true;
          row = row * 10 + s[j] - '0';
        } else if (checker && s[j] >= '0' && s[j] <= '9')
          col = col * 10 + s[j] - '0';
        else if (digit && s[j] == 'C')
          checker = true;
      }
      label(col);
      printf("%d\n", row);
    } else {
      for (int j = 0; j < len; j++) {
        if (s[j] >= 'A' && s[j] <= 'Z')
          col = col * 26 + s[j] - 'A' + 1;
        else
          row = row * 10 + s[j] - '0';
      }
      printf("R%dC%d\n", row, col);
    }
  }
  return 0;
}
