#include <bits/stdc++.h>
using namespace std;
int get_type(string s) {
  char a = s.at(1);
  if (s.at(0) == 'R' && s.at(1) <= '9') {
    int flag = 0;
    for (int i = 2; i < s.length(); i++) {
      if (s.at(i) == 'C') {
        flag = 1;
        break;
      }
    }
    if (flag) return 1;
  }
  return 2;
}
int get_row_num(string s, int type) {
  int row_num = 0;
  if (type == 1) {
    int i = 1;
    while (s.at(i) != 'C') {
      int num = (s.at(i) - '0');
      row_num = row_num * 10 + num;
      i++;
    }
    return row_num;
  } else {
    int i = 0;
    while (s.at(i) > '9') i++;
    while (i < s.length()) {
      int num = (s.at(i) - '0');
      row_num = row_num * 10 + num;
      i++;
    }
    return row_num;
  }
}
string get_col_num_to_string(int col) {
  string res;
  while (col) {
    col--;
    int a = col % 26;
    char c = 'A' + (a);
    res = c + res;
    col = col / 26;
  }
  return res;
}
int get_col_num_from_string(string s) {
  int i = 0;
  int col_num = 0;
  while (s.at(i) > '9') {
    int a = s.at(i) - 'A';
    a++;
    col_num = col_num * 26 + a;
    i++;
  }
  return col_num;
}
void solve(string s) {
  int type = get_type(s);
  if (type == 1) {
    int row_num = get_row_num(s, type);
    int i = s.length() - 1;
    while (s.at(i) != 'C') i--;
    int col_num = 0;
    i++;
    while (i < s.length()) {
      int num = s.at(i) - '0';
      col_num = col_num * 10 + num;
      i++;
    }
    string col = get_col_num_to_string(col_num);
    cout << col << row_num;
    return;
  } else {
    int row_num = get_row_num(s, type);
    int col = get_col_num_from_string(s);
    cout << 'R' << row_num << 'C' << col;
  }
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    solve(s);
    cout << endl;
  }
}
