#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, x = 0, y = 0, k = 0, j, flag, del, ost = 0, m = 26;
  string s;
  char *c = &s[0], y1[20];
  cin >> n;
  for (i = 0; i < n; i++) {
    k = 1;
    flag = 0;
    y = 0;
    x = 0;
    cin >> s;
    c = &s[0];
    for (j = 0; j < s.length(); j++) {
      if ((s[j] == 'R') && (s[j + 1] <= '9')) flag++;
      if ((s[j] == 'C') && (s[j + 1] <= '9')) flag++;
      if (flag == 2) break;
    }
    if (flag == 2) {
      while (*(++c) != 'C') {
        x = (x * 10) + int(*c) - int('0');
      }
      while (*(++c) != '\0') {
        y = (y * 10) + int(*c) - int('0');
      }
      while (y > 0) {
        del = exp(k * log(m));
        ost = (y % del) * m / del;
        if (ost == 0) ost = m;
        y1[k - 1] = char(ost + int('A') - 1);
        y -= (ost * del / m);
        k++;
      }
      for (j = 1; j < k; j++) {
        cout << y1[k - j - 1];
        y1[k - j - 1] = ' ';
      }
      cout << x << endl;
    } else {
      cout << "R";
      while (*c >= 'A') {
        y = (y * 26) + int(*c) - int('A') + 1;
        c++;
      }
      while (*c != '\0') {
        cout << *c;
        c++;
      }
      cout << "C" << y << endl;
    }
  }
  return 0;
}
