Link: http://codeforces.com/problemset/problem/1/ B

B. spreadsheetstime limit per test10 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

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 follow*N*Lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106.

Output

Write*N*Lines, each line shoshould contain a cell coordinates in the other numeration system.

Sample test (s) Input

2R23C55BC23

Output

BC23R23C55

Question:

Two different expression methods are used to represent the rows and columns!

The Code is as follows:

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 117; typedef _ int64 ll; int is_letter (char C) {If (C> = 'A' & C <= 'Z') return 1; return 0;} int is_num (char C) {If (C> = '0' & C <= '9') return 1; return 0 ;}int main () {ll t; char s [maxn]; scanf ("% i64d", & T); getchar (); While (t --) {gets (s); int Len = strlen (s); int K = 0; for (INT I = 0; I <Len; I ++) {If (is_letter (s [I]) & is_num (s [I + 1]) {k ++ ;}}if (k = 2) // r23c55 FORM {ll I, j; ll T1 = 0, T2 = 0; for (I = 1 ;; I ++) {If (is_num (s [I]) T1 = T1 * 10 + s [I]-'0'; else break ;} for (j = I + 1; j <Len; j ++) {If (is_num (s [J]) t2 = T2 * 10 + s [J]-'0'; else break;} // printf ("T1: % i64d t2: % i64d \ n", T1, t2); char a [maxn]; I = 0; while (T2) {ll TT = t2 % 26; A [I ++] = tt + 'a'-1; t2/= 26; If (TT = 0) // note {T2 --; A [I-1] = 'Z' ;}} for (j = I-1; j> = 0; j --) {printf ("% C", a [J]);} printf ("% i64d \ n", T1 );} else // bc23 FORM {ll I, j; ll T3 = 0, T4 = 0; for (I = 0; I ++) {If (is_num (s [I]) break; T3 = T3 * 26 + (s [I]-'A' + 1) ;}for (j = I; j <Len; j ++) {t4 = T4 * 10 + s [J]-'0';} printf ("R % i64dc % i64d \ n", T4, t3) ;}} return 0;}/* 99r23c55bc23r26c78bz26 */

Codeforces 1b. Spreadsheets (simulation)