#include <bits/stdc++.h>
int main() {
  long m;
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    char a[1000];
    int k;
    long h;
    long h1;
    int o;
    char b[1000];
    char c[1000];
    scanf("%s", a);
    k = strlen(a);
    int l;
    int f = 0;
    int y;
    int y1;
    for (l = 1; l < k; l++) {
      if (a[l - 1] <= 57 && a[l] == 'C') {
        f = 1;
        y = l;
        break;
      }
    }
    if (f == 1) {
      for (l = 1; l < y; l++) b[l - 1] = a[l];
      b[y - 1] = '\0';
      h = atoi(b);
      for (l = y + 1; l <= k; l++) b[l - y - 1] = a[l];
      h1 = atoi(b);
      for (l = 0;; l++) {
        if (h1 == 0) break;
        if (h1 % 26 == 0) {
          c[l] = 'Z';
          h1 = h1 / 26;
          h1--;
        } else {
          c[l] = h1 % 26 + 64;
          h1 = h1 / 26;
        }
      }
      for (o = l - 1; o >= 0; o--) printf("%c", c[o]);
      printf("%ld\n", h);
    } else {
      double w;
      double shu = 0;
      double d = 0;
      for (l = 0; l < k; l++)
        if (a[l - 1] > 64 && a[l] < 58) {
          y1 = l;
          break;
        }
      for (l = y1 - 1; l >= 0; l--) {
        w = (a[l] - 64) * 1.0;
        shu += pow(26.0, d) * w;
        d++;
      }
      printf("R");
      for (l = y1; l < k; l++) printf("%c", a[l]);
      printf("C%.0f", shu);
      printf("\n");
    }
  }
}
