#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
bool check(string str)
{
return (str[0] == 'R' && str[1] > '0' && str[1] < '10');
}
int main()
{
int T;
cin >> T;
while (T--)
{
string str;
cin >> str;
bool isRC = check(str);
if (isRC)
{
int len = str.size();
int pos;
for (int i = 0; i < len; i++)
{
if (str[i] == 'C')
{
pos = i;
break;
}
}
int row = 0;
for (int i = 1; i < pos; i++)
{
int t = str[i] - 48;
row = (row * 10 + t);
}
int col = 0;
for (int i = pos + 1; i < len; i++)
{
int t = str[i] - 48;
col = (col * 10 + t);
}
int j = 0;
int t[101];
for (; col; col = col / 26 - !(col % 26))
{
if (col % 26)
t[++j] = col % 26;
else
t[++j] = 26;
}
for (; j; j--)
{
cout << s[t[j] - 1];
}
cout << row << endl;
}
else
{
int len = str.size();
int pos;
for (int i = 0; i < len; i++)
{
if (str[i] > '0' && str[i] <= '9')
{
pos = i;
break;
}
}
int row = 0;
for (int i = pos; i < len; i++)
{
int t = str[i] - 48;
row = (row * 10 + t);
}
int col = 0;
int cnt = 0;
for (int i = pos - 1; i >= 0; i--)
{
int t = str[i] - 'A' + 1;
col += (pow(26, cnt++) * t);
}
cout << "R" << row << "C" << col << endl;
}
}
return 0;
}