Codeforces 1B

POSTS

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <vector>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

#define fe(i, a, b) for (int i = int(a); i <= int(b); i++)
#define fu(i, a, b) for (int i = int(a); i < int(b); i++)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair

void solve2(string s)
{
    int rv = 0, cv = 0;
    for (int i = 0; i < s.size(); i++) {
        if (!isdigit(s[i])) {
            cv = cv * 26 + s[i] - 'A' + 1;
        } else {
            rv = rv * 10 + s[i] - '0';
        }
    }
    cout << "R" << rv << "C" << cv << endl;
}

void pc(int a)
{
    if (a == 0 || a == 26) {
        cout << 'Z';
        return;
    }
    if (a < 26) {
        printf("%c", 'A' + a - 1);
        return;
    }
    if (a % 26) {
        pc(a / 26);
        pc(a % 26);
    } else {
        pc(a / 26 - 1);
        pc(a % 26);
    }
    return;
}

void solve4(string s)
{
    int rv = 0;
    int cv = 0;
    int i;
    for (i = 1; s[i] != 'C'; i++) {
        rv = rv * 10 + s[i] - '0';
    }
    for (i = i + 1; i < s.size(); i++) {
        cv = cv * 10 + s[i] - '0';
    }
    //cout << cv << endl;
    pc(cv);
    cout << rv << endl;
}

void solve(string s)
{
    short last_type = 0;
    short current_type;
    vector<char> vc;
    for (int i = 0; i < s.size(); i++) {
        if (isdigit(s[i])) current_type = 0;
        else current_type = 1;
        if (last_type != current_type) {
            vc.pb(s[i]);
        }
        last_type = current_type;
    }
    if (vc.size() == 4) solve4(s);
    else solve2(s);
}

int main()
{
    int n;
    string s;
    cin >> n;
    while (n--) {
        cin >> s;
        solve(s);
    }

    return 0;
}