#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  for (long long int x = 1; x <= n; x++) {
    string s;
    cin >> s;
    string s1 = "", s3 = "";
    long long int num2 = 0, num4 = 0;
    long long int i = 0;
    while (i < s.length() && s[i] >= 'A' && s[i] <= 'Z') {
      s1 += s[i];
      i++;
    }
    while (i < s.length() && s[i] >= '0' && s[i] <= '9') {
      num2 = num2 * 10 + (s[i] - '0');
      i++;
    }
    while (i < s.length() && s[i] >= 'A' && s[i] <= 'Z') {
      s3 += s[i];
      i++;
    }
    while (i < s.length() && s[i] >= '0' && s[i] <= '9') {
      num4 = num4 * 10 + (s[i] - '0');
      i++;
    }
    if (s3 == "") {
      long long int row = num2;
      long long int column = 0;
      long long int mul = 1;
      for (long long int y = s1.length() - 1; y >= 0; y--) {
        column += ((long long int)(s1[y] - 'A' + 1)) * mul;
        mul = mul * 26;
      }
      cout << "R" << row << "C" << column << endl;
    } else {
      string column = "";
      while (num4 != 0) {
        long long int rem = num4 % 26;
        if (rem == 0) {
          rem = 26;
          num4--;
        }
        column = (char)(rem + 'A' - 1) + column;
        num4 /= 26;
      }
      cout << column << num2 << endl;
    }
  }
}
