CF1B Spreadsheets
//26进制与10进制之间的相互转换
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e6 + 10;
bool find(string s)
{
bool x = false, y =false, z = false;
for(int i = 0; i < s.size(); i ++)
{
if(s[0] == 'R')
{
x = true;
}
if(x == true && s[i] <= '9' && s[i] >= '0')y = true;
if(y == true && s[i] == 'C')
{
return z;
}
}
z = true;
return z;
}
int main()
{
int n;
cin >>n;
while(n --)
{
string s;
cin >> s;
if(find(s))
{
int l = 0, r = 0, c = 0;
for(int i = 0; i < s.size(); i ++)
if(s[i] >= 'A' && s[i] <= 'Z')l ++;
int num = 1;
for(int i = l - 1; i >= 0; i --){c += (s[i] - 'A' + 1) * num, num *= 26;}
num = 1;
for(int i = s.size() - 1; i >= l; i --)r += (s[i] -'0') * num, num *= 10;
printf("R%dC%d\n",r,c);
}
else {
string ss = "";
int l = 0, r = 0, c = 0;
for(int i = 1; l < s.size(); i ++)
if(s[i] <= '9' && s[i] >= '0')l ++;
else break;
int num = 1;
for(int i = l; i >= 1; i --)r += (s[i] -'0') * num, num *= 10;
num = 1;
for(int i = s.size() - 1; i >= l + 2; i --)c += (s[i] - '0') * num, num *= 10;
while(c > 0)
{
if(c % 26 != 0)ss += (c % 26 + 'A' - 1);
else ss += 'Z', c -= 1;//注意当余数为0时,是Z,而且要 -1, 因为不减的话, 下面一位就会比原来多出来一个
c /= 26;
}
reverse(ss.begin(), ss.end());
cout << ss<< r <<endl;
}
}
}