n = int(input())
alpha = "ZABCDEFGHIJKLMNOPQRSTUVWXY"
for _ in range(n):
s = input()
ft = 1 if s[0] == "R" and s[1].isdigit() and "C" in s else 2
if ft == 1:
idx = s.index("C")
r = (s[1:idx])
c = int(s[idx+1:])
cs = ""
while c > 0:
cs = alpha[c % 26] + cs
if c % 26 == 0: c-=1
c = c//26
print(cs+r)
else:
for i in range(len(s)):
if s[i].isdigit():
break
cs = s[:i]
r = s[i:]
csi = 0
for c in cs:
idx = alpha.index(c)
idx = idx if idx != 0 else 26
csi *= 26
csi+=idx
print("R"+r+"C"+str(csi))
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define sare(v) (v).begin(), (v).end()
#define MOD 1000000007
//#define fastio() ios_base::sync_with_stdio(0), cin.tie(0)
const int N=5e5+10;
//------------------------THINGS_TO_REMEMBER---------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//######## -> M_PI = value of pi
//######## -> INT_MAX=1e18
//######## -> ll = 10^-18 - 10^18
//-----------------------DEFINED FUNCTIONS----------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
ll gcd(ll a, ll b)
{if(max(a,b)%min(a,b)==0) return min(a,b);
while(1)
{ if(a>b) {a=a-b; if(b%a==0) return a;}
else {b=b-a; if(a%b==0) return b;} }}
bool prime(ll &n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
//---------------------------DFS---------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
vector <ll> g[N];
vector <ll> visited(N);
void dfs(ll vertex)
{
// action on vertex after entering
if(visited[vertex]) return;
visited[vertex]++;
for(auto child: g[vertex])
{
// action on child before entering child
dfs(child);
// action on child after exiting the child
}
// action on vertex after before exiting vertex
}
*/
//---------------------------BFS---------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
vector <ll> g[N];
vector <ll> visited(N);
vector <ll> level(N);
void bfs(ll source)
{
queue <ll> q;
q.push(source);
visited[source]=1;
while(!q.empty())
{
ll curr_v = q.front();
q.pop();
for(ll child:g[curr_v])
{
if(!visited[child])
{
q.push(child);
visited[child]++;
level[child]=level[curr_v]+1;
}
}
}
}
*/
//---------------------------seive-----------------------------------------
/*
bool se[N];
for(ll i=2;i<=N;i++)
{
se[i]=true;
}
for(ll i=2;i<=N;i++)
{
if(se[i]==true)
{
for(ll j=i*i;j<=N;j+=i)
se[j]=false;
}
}
*/
//----------------------BINARY INDEX TREE---------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*deque <ll> bit(N);
ll n;
void update1(ll i,ll x)
{
ll ans=x*i;
for(;i<=n;i+=(i&(-i)))
{
bit[i]=ans;
ans+=x;
}
}
void update (ll i,ll x)
{
for(;i<=n;i+=(i&(-i)))
{
bit[i]+=x;
}
}
ll sum(ll i)
{
ll ans=0;
for(;i>0;i-=(i&(-i)))
{
ans+=bit[i];
}
return ans;
}
*/
string code(ll n)
{
string ans;
if(n<=26)
{
char c='A'+(n-1);
ans.pb(c);
}
while(n>26)
{
ll r=n%26;
n=n/26;
if(r==0)
{
ans.pb('Z');
n--;
}
else
{
char c='A'+r; c--;
ans.pb(c);
}
if(n<=26)
{
char c='A'+(n-1);
ans.pb(c);
}
}
reverse(all(ans));
return ans;
}
ll decode(string s)
{
ll ans=0,t=1;
for(int i=s.size()-1;i>=0;i--)
{
ans=ans+((s[i]-'A')+1)*t;
t*=26;
}
return ans;
}
//--------------------------------solve---------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
void solve()
{
string s; bool f=true;
cin>>s;
map <char,ll> mp;
for(int i=0;i<s.size();i++)
{
mp[s[i]]++;
}
if(mp['R']&&mp['C']&&(s[1]<'A'||s[1]>'Z')) f=false;
//f=true = type 1
if(f)
{
ll i=0,temp=0;
string a;
while(s[i]>='A'&&s[i]<='Z')
{
a.pb(s[i]);
i++;
}
while(i<s.size())
{
temp=temp*10+(s[i]-'0');
i++;
}
cout<<"R"<<temp<<"C"<<decode(a)<<endl;
}
//f=false = type 2
else
{
ll i=1,x=0,y=0;
while(s[i]!='C')
{
x=x*10+(s[i]-'0');
i++;
}
i++;
while(i<s.size())
{
y=y*10+(s[i]-'0');
i++;
}
cout<<code(y)<<x<<endl;
}
}
//------------------------INT_MAIN-------------------------------------
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
int main()
{
int T = 1;
cin >> T;
while(T--){
solve();
}
return 0;
}
1632B - Roof Construction | 388A - Fox and Box Accumulation |
451A - Game With Sticks | 768A - Oath of the Night's Watch |
156C - Cipher | 545D - Queue |
459B - Pashmak and Flowers | 1538A - Stone Game |
1454C - Sequence Transformation | 165B - Burning Midnight Oil |
17A - Noldbach problem | 1350A - Orac and Factors |
1373A - Donut Shops | 26A - Almost Prime |
1656E - Equal Tree Sums | 1656B - Subtract Operation |
1656A - Good Pairs | 1367A - Short Substrings |
87A - Trains | 664A - Complicated GCD |
1635D - Infinite Set | 1462A - Favorite Sequence |
1445B - Elimination | 1656C - Make Equal With Mod |
567A - Lineland Mail | 1553A - Digits Sum |
1359B - New Theatre Square | 766A - Mahmoud and Longest Uncommon Subsequence |
701B - Cells Not Under Attack | 702A - Maximum Increase |