Algorithm


B. Spreadsheets
time limit per test
10 seconds
memory limit per test
64 megabytes
input
standard input
output
standard 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 should contain a cell coordinates in the other numeration system.

Examples
input
Copy
2
R23C55
BC23
output
Copy
BC23
R23C55



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <vector>
#include <string>


long convertToNumeric(std::string input){

    long output(0);
    const int alphaSize(26);
    for(int k = 0; k < input.size(); k++){output = alphaSize * output + (input[k] - 'A' + 1);}
    return output;
}


std::string convertToAlpha(long input){

    const int alphaSize(26);
    std::string output("");

    while(input > 0){
        char letter = 'Z';
        long inputMod = input % alphaSize;
        if(inputMod > 0){letter = 'A' + inputMod - 1;}
        else{input -= alphaSize;}
        input = input / alphaSize;
        output = letter + output;
    }

    return output;
}

int main(){
    int n; scanf("%d\n", &n);
    while(n--){
        std::string line; getline(std::cin, line);

        bool coordinates(0);
        if(line[0] == 'R' && ('0' <= line[1] && line[1] <= '9') && 1 < line.find('C') && line.find('C') < line.size() - 1){coordinates = 1;}

        if(coordinates){
            int cPos = line.find('C');
            std::string rowString = line.substr(1, cPos - 1);  
            std::string colString = line.substr(cPos + 1);  
            long col = atol(colString.c_str());
            std::cout <<  convertToAlpha(col) << rowString << std::endl;
        }
        else{
            
            std::string rowString = "";
            std::string colString = "";

            for(int k = 0; k < line.size(); k++){
                if('0' <= line[k] && line[k] <= '9'){colString = line.substr(k);break;}
                else{rowString += line[k];}
            }
            std::cout << "R" << colString << "C" <<  convertToNumeric(rowString) << std::endl;
        }
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
R23C55
BC23

Output

x
+
cmd
BC23
R23C55
Advertisements

Demonstration


Codeforces Solution-B. Spreadsheets-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+