In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
Input
The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follown lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than106 .
Output
Write n lines, each line should contain a cell coordinates in the other numeration system.
Example
Input
2
R23C55
BC23
Output
BC23
R23C55
#include<stdio.h>
#include<string.h>
char a[1024]={'\0'};
void f1()
{
int x=0,y=0,i=1;
while(a[i]!='C')
{
y=y*10+(a[i]-'0');
i++;
}
i++;
while(a[i]!='\0')
{
x=x*10+(a[i]-'0');
i++;
}
int c[1024]={0};
i=0;
while(x)
{
if(x%26)
{
c[i]=x%26;
x/=26;
}
else
{
c[i]=26;
x/=26;
x--;
}
i++;
}
for(i--;i>=0;i--)
printf("%c",c[i]+'A'-1);
printf("%d\n",y);
}
void f2()
{
int i;
int x,y;
x=y=0;
for(i=0;a[i]>'9';i++)
{
y=y*26+(a[i]-'A'+1);
}
for(;a[i]!='\0';i++)
{
x=x*10+(a[i]-'0');
}
printf("R%dC%d\n",x,y);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int flag=0,i=1;
scanf("%s",a);
if(a[0]=='R' && a[1]<'A')
{
while(a[i]<'A' && a[i]!='\0')i++;
flag=1;
}
if(i!=strlen(a) && flag)
f1();
else
f2();
memset(a,0,sizeof(a));
}
return 0;
}