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.

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 .

Write n lines, each line should contain a cell coordinates in the other numeration system.

let rec base_26 a =
  if a = 0 then [0]
  else if a < 0 then []
  else (a mod 26) :: (base_26 (a / 26 - 1))

let inv26 a =
  let n = String.length a in
  let r = ref 0 in
  for i = 0 to (n-1) do
    r := !r * 26 + (Char.code a.[i] - 64)
  done;
  !r

let rec implode lc =
  match lc with
  |[] -> ""
  |c::t -> Printf.sprintf "%c%s" c (implode t)

let convert_nb n =
  let n = int_of_string n in
  let l = List.rev (base_26 (n - 1)) in
  implode (List.map (fun n -> Char.chr (n + 65)) l)

let () =
  let s = read_line () in
  let n = int_of_string s in
  for i = 0 to (n-1) do
    let s = read_line () in
    if Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0 then begin
      let s = String.sub s 1 (String.length s - 1) in
      let [a;b] = Str.split (Str.regexp "C") s in
      Printf.printf "%s%s\n" (convert_nb b) a
    end else begin
      ignore (Str.search_forward (Str.regexp "[A-Z]+") s 0);
      let a = Str.matched_string s in
      ignore (Str.search_forward (Str.regexp "[0-9]+") s 0);
      let b = Str.matched_string s in
      Printf.printf "R%sC%i\n" b (inv26 a)
    end
  done;

let (|>) x f = f x

let is_letter char =
  match char with
      'A'..'Z' -> true
    | _ -> false

let is_digit char =
  match char with
      '0'..'9' -> true
    | _ -> false

let parse_pair s pos =
  let rec parse pred p =
    if p < String.length s && pred (String.get s p)
    then parse pred (p+1)
    else p
  in
  let pos1 = parse is_letter pos in
  let pos2 = parse is_digit pos1 in
  ((String.sub s pos (pos1 - pos), String.sub s pos1 (pos2 - pos1)), pos2)

let colrow_to_rowcol (col, row) =
  let int_of_letters letters =
    let res = ref 0 in
    String.iter (fun c -> res := !res * 26 + (int_of_char c) - 64) letters;
    !res
  in
  Printf.sprintf "R%dC%d" (int_of_string row) (int_of_letters col)

let rowcol_to_colrow (_, row) (_, col) =
  let rec letters_of_int n acc =
    if n = 0
    then acc
    else letters_of_int ((n-1) / 26) ((String.make 1 (char_of_int (65 + ((n-1) mod 26)))) ^ acc)
  in
  Printf.sprintf "%s%s" (letters_of_int (int_of_string col) "") row

let convert s =
  let pair1, pos = parse_pair s 0 in
  if pos = String.length s
  then colrow_to_rowcol pair1
  else let pair2, _ = (parse_pair s pos) in
    rowcol_to_colrow pair1 pair2

let iterate n =
  for i = 1 to n do
    read_line ()
    |> convert
    |> Printf.printf "%s\n"
  done

let _=
  read_int ()
  |> iterate

open Printf
open Scanf

type coord =
  | RC of int * int (* row, column *)
  | Concat of string * int (* column, row *)

let parse: string -> coord =
  fun s ->
  if (Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0) then
    let sep = Str.search_forward (Str.regexp "C[0-9]+") s 0 in
    let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in
    let b = int_of_string (Str.string_after s (sep + 1)) in
    RC (a, b)
  else
    let sep = Str.search_forward (Str.regexp "[0-9]+") s 0 in
    let a = Str.string_before s sep in
    let b = int_of_string (Str.string_after s sep) in
    Concat (a, b)

let pp: coord -> string =
  fun c ->
  match c with
  | RC(a, b) -> "R" ^ (string_of_int a) ^ "C" ^ (string_of_int b)
  | Concat(a, b) -> a ^ (string_of_int b)

let translate: coord -> coord =
  let char_to_num c = (Char.code c) - (Char.code 'A') + 1in
  let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in
  let num_to_str_system n =
    let rec inner i s =
      let d = i / 26
      and r = i mod 26 in
      if d > 0 then
        if r = 0 then
          if d > 1 then
          inner (d - 1) ((String.make 1 'Z') ^ s)
          else ((String.make 1 'Z') ^ s)
        else
          inner d ((String.make 1 (num_to_char r)) ^ s)
      else
        (String.make 1 (num_to_char r)) ^ s
    in
    inner n ""
  in
  let str_to_num_system s =
    let rec inner s =
      if (String.length s > 1) then
        (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))
      else
        (char_to_num s.[String.length s - 1])
    in
    inner s
  in
  fun c ->
  match c with
  | RC(a, b) -> Concat(num_to_str_system b, a)
  | Concat(a, b) -> RC(b, str_to_num_system a)

let main () =
  let input = input_line stdin in
  let n = sscanf input "%i" (fun x -> x) in
  for i = 1 to n do
    let input = input_line stdin in
    let s = sscanf input "%s" (fun x -> x) in
    let c = parse s in
    let t = translate c in
    printf "%s\n" (pp t);
  done

let _ = main ()

let (|>) x f = f x

let rc2xls r c =
  let rec go c acc =
    if c = 0 then
      String.concat "" acc
    else
      let t = (c-1) mod 26 in
      go ((c-t-1)/26) (String.make 1 (Char.chr (t+65))::acc)
  in String.concat "" [go c []; string_of_int r]

let foldl f acc s =
  let n = String.length s in
  let rec go i acc =
    if i >= n then
      acc
    else
      go (i+1) (f acc s.[i])
  in go 0 acc

let xls2rc r c =
  String.concat "" ["R"; string_of_int c; "C"; string_of_int (foldl (fun acc x -> acc*26+(Char.code x-64)) 0 r)]

let () =
  for i = 1 to read_int () do
    let s = read_line () in
    try
      Scanf.sscanf s "R%dC%d" (fun r c ->
        rc2xls r c |> print_endline
      )
    with _ ->
      Scanf.sscanf s "%[A-Z]%d" (fun r c ->
        xls2rc r c |> print_endline
      )
  done

let n = read_int () ;;
let r = Str.regexp "R[0-9]+C[0-9]+" ;;
for i = 1 to n do
       let coord = read_line () in
       let is_first = Str.string_match r coord 0 in
       if is_first then begin
               let coords = Str.split (Str.regexp "[A-Z]") coord in
               let col = int_of_string (List.nth coords 0) in
               let row = int_of_string (List.nth coords 1) in
               let buf1 = Buffer.create 1000 in
               let rec rstring num buf =
                       let r = num mod 26 in
                       if (num/26) = 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               Buffer.contents buf
                       end
                       else if r != 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               rstring (num/26) buf
                       end
                       else if ((num-1)/26) != 0 then begin
                           let _ = Buffer.add_char buf 'Z' in
                           rstring ((num-1)/26) buf
                       end
                       else begin
                               let _ = Buffer.add_char buf 'Z' in
                               Buffer.contents buf
       end in

               let rec rev s =
                       let sl = String.length s in
                       for j=0 to (sl-1)/2 do
                               let c = s.[j] in
                               s.[j] <- s.[sl-j-1];
                               s.[sl-j-1] <- c;
                       done;
                       s in
               let row_s = rev (rstring (row) (Buffer.create 2)) in
               let _ = Printf.printf "%s%d\n" row_s col in

               row
       end
       else begin
               let rec row str j runner =
                       let fchar = Char.code str.[j] in
                       let schar = Char.code str.[j+1] in
                       if schar >= 65 then
                               let runner = runner + fchar-64 in
                               row str (j+1) (runner*26)
                       else
                               runner + fchar - 64 in
               let rnum = row coord 0 0 in
               let cpos = Str.search_forward (Str.regexp "[0-9]+") coord 0 in
               (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in
               *)
               let cstring = Str.matched_string coord in
               let cint = int_of_string cstring in
               let _ = Printf.printf "R%dC%d\n" cint rnum in
               1
       end
done;

open Scanf;;
open String;;

type cell = RC | NRC;;

let print_cell t = match t with
    RC -> print_endline "RC"
   |NRC -> print_endline "NRC"

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;

let ntostring=[|"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z"|];;

let myindex s c = try index s c with Not_found -> -100;;

let is_digit = function
    '0'..'9' -> true
  |_ -> false;;

let  rec digit_index x ind =
     let len = length x in
     match len with
     | 0 -> ind
     | _  -> match get x 0 with
       | '0' .. '9' -> ind
       |_ -> digit_index (sub x 1 (len - 1) ) (ind + 1)
;;
let rec process_RC x =
  let (rown,coln) = get_num x in
  print_string (convert_to_AB coln); print_string (string_of_int rown); print_endline "";
and get_num x = let m = index x 'C' in
  let tmp = (length x) - m -1 in
  let tmp1 = match tmp with
    | x when x <=0 -> 1
    |_ -> int_of_string (sub x (m+1) tmp)
  in
  (int_of_string (sub x 1 (m-1)), tmp1)
and convert_to_AB x =
  let y = ref x in
  let ss = ref "" in
  let () =
    while !y > 0  do
      let tmp = ((!y-1) mod 26) in
      y := (!y - tmp - 1) / 26;
      ss := ntostring.(tmp) ^ !ss
    done in !ss;;

let rec process_NRC x =
  let (ab,row) = get_content x in
  print_char 'R'; print_string (string_of_int row); print_char 'C';
  print_string(string_of_int  (convert_to_int ab));
  print_endline "";
and get_content x =
  let m = digit_index x 0 in
  let tmp=(length x) -m in
  let tmp2 = match tmp with
    |0 -> 1
    |_ -> int_of_string (sub x m tmp) in
  (sub x 0 m, tmp2)
and convert_to_int x =
  let k = ref ((length x) - 1) in
  let mul = ref  1 in
  let acc = ref  0 in
  let nA = int_of_char 'A' in
  let () =
    while !k >=0 do
      let f = get x !k in
      let g = (int_of_char f) - nA + 1 in
      acc := !acc +  g*(!mul); mul:= !mul* 26; k:=!k-1
    done in !acc
;;

let  process t s = match t with
    RC -> process_RC s
   |NRC -> process_NRC s
;;

for i=1 to n do
  let ms = ref (String.make 32 'A') in
  let () =
    ms  := Scanf.bscanf Scanf.Scanning.stdin "%s " (fun x -> x)
  in
  let t = match (myindex !ms 'R', myindex !ms 'C')  with
    | (-100, _) -> NRC
    | (_,-100) -> NRC
    | (a, b)  -> if  b - a > 1 && (is_digit  (get !ms (a+1))) then RC else NRC
  in (*print_string ! ms; print_string " :  ";*) process t !ms
done;;

type mode =
      S0
    | S1 of string
    | S2 of string * int
    | S3
    | S4 of int
    | S5 of int
    | S6 of int * int

type ('a, 'b) either = Left of 'a | Right of 'b

let _ =
    let n = read_int () in
    let c2s c = String.make 1 c in
    let s2i s =
        let l = String.length s in
        let rec loop i acc =
            if i = l then acc else loop (i + 1) (acc * 26 + int_of_char s.[i] - 64)
        in
        loop 0 0
    in
    let i2s a =
        let rec loop i acc =
            if i = 0 then acc else loop ((i - 1) / 26) (c2s (char_of_int (((i - 1)mod 26) + 65)) ^ acc)
        in
        loop a ""
    in
    let conv s =
        let s = s ^ "." in
        let rec loop i mode =
            match mode, s.[i] with
            | S0,        'R'                -> loop (i + 1) S3
            | S0,        k                  -> loop (i + 1) (S1 (c2s k))
            | S1 a,      ('0' .. '9' as k)  -> loop (i + 1) (S2 (a, int_of_char k - 48))
            | S1 a,      k                  -> loop (i + 1) (S1 (a ^ c2s k))
            | S2 (a, b), '.'                -> Left (a, b)
            | S2 (a, b), ('0' .. '9' as k)  -> loop (i + 1) (S2 (a, b * 10 + int_of_char k - 48))
            | S3,        ('0' .. '9' as k)  -> loop (i + 1) (S4 (int_of_char k - 48))
            | S3,        k                  -> loop (i + 1) (S1 ("R" ^ c2s k))
            | S4 a,      ('0' .. '9' as k)  -> loop (i + 1) (S4 (a * 10 + int_of_char k - 48))
            | S4 a,      '.'                -> Left ("R", a)
            | S4 a,      'C'                -> loop (i + 1) (S5 a)
            | S5 a,      ('0' .. '9' as k)  -> loop (i + 1) (S6 (a, int_of_char k - 48))
            | S6 (a, b), ('0' .. '9' as k)  -> loop (i + 1) (S6 (a, b * 10 + int_of_char k - 48))
            | S6 (a, b), '.'                -> Right (a, b)
            | _                             -> failwith "Illegal transition"
        in
        match loop 0 S0 with
        | Left  (a, b) -> Printf.sprintf "R%dC%d" b (s2i a)
        | Right (a, b) -> Printf.sprintf "%s%d" (i2s b) a
    in
    for i = 1 to n do
        let s = read_line () in
        print_endline (conv s)
    done

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
      beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0)  then
    (int_of_string one):: (returnIntList t "")
      else returnIntList t (one^h)
  | _ -> (int_of_string one)::[]

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec checkInCHere str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub s 0 1) "C" == 0)
      then true
    else if (Char.code(String.get s 0) > 64) then false
    else checkInCHere (String.sub s 1 (String.length s - 1))

let checkIsRC str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "R" == 0) && (Char.code(String.get s 1)<65)
    then checkInCHere (String.sub str 2 (String.length str - 2))
    else false

let rec reverseList li o =
  match li with
  | [] -> o
  | h :: t -> reverseList t (h :: o)

let returnConvertedCol k =
  let rec returnIt s =
    if (s > 0) then
      let n = s / 26 in
      let r = s mod 26 in
      (string_of_int r) :: returnIt n
    else [] in
  reverseList (returnIt (int_of_string k)) []

let returnConvertedRow n =
  let rec returnIt s =
    let k = s mod 26 in
    if (s > 0) then
      if (k == 0) then 'Z' :: (returnIt((s-26)/26))
      else
        (Char.chr (k+64)) :: (returnIt (s/26))
    else
      [] in
  reverseList (returnIt (int_of_string n)) []

let rec printList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_string h; printList t

let rec printCharList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_char h; printCharList t

let changeRCToAlph line =
  let rec newline l row col=
    if (compare (String.sub l 0 1) "C") == 0 then
      (row, String.sub l 1 (String.length l -1))
    else
      let newRow = row ^ (String.sub l 0 1) in
      newline (String.sub l 1 (String.length l -1))
      newRow col in
  let (r,c) = newline line "" ""  in
  let rList = returnConvertedRow c in
  printCharList rList; print_string r; print_string "\n"

let changeStringToAscii n =
  let rec returnStringToNum str num =
    match str with
    | "" -> num
    | s ->
      returnStringToNum (String.sub s 1 (String.length str - 1))
      ((Char.code(String.get s 0) - 64) + 26*num) in
  string_of_int (returnStringToNum n 0)

let changeAlphToRC line =
  let rec newline l row =
    if Char.code(String.get l 0) < 65 then
    (row, l)
    else
    newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in
  let (r,c) = newline line "" in
  print_char 'R';print_string c;print_char 'C';
  print_string(changeStringToAscii r);print_string"\n"

let n = read_int()

let check line =
  if (checkIsRC line) then
    changeRCToAlph(String.sub line 1 (String.length line -1))
  else
    changeAlphToRC line

let rec strList num =
  if (num > 0) then
    let k = read_line() in
    let _ = check k in
    strList (num-1)
  else
    print_string""
let _ = strList n

open Char;;
open String;;

let letters_of_num col =
  let rec letters_of_num' col =
    if col < 26 then Char.escaped (chr (col + code 'A'))
    else (letters_of_num' (col / 26 - 1)) ^ (letters_of_num' (col mod 26)) in
  letters_of_num' (col - 1);;

let solve_1 row col = letters_of_num (int_of_string col) ^ row;;

let rec pow a = function
  | 0 -> 1
  | 1 -> a
  | n ->
    let b = pow a (n / 2) in
    b * b * (if n mod 2 = 0 then 1 else a);;

let num_of_letters ls =
  let rec num_of_letters' ls =
    if length ls == 1 then code (get ls 0) - code 'A'
    else
      let hd = sub ls 0 1 in
      let tl = sub ls 1 ((length ls) - 1) in
      (pow 26 (length ls - 1)) * (1 + num_of_letters' hd) + (num_of_letters' tl) in
  num_of_letters' ls + 1;;

let solve_2 row col = "R" ^ row ^ "C" ^ (string_of_int (num_of_letters col));;

let solve: string -> string = fun s ->
  let open Str in
  let r_1 = regexp "^R\\([0-9]+\\)C\\([0-9]+\\)$" in
  let r_2 = regexp "^\\([A-Z]+\\)\\([0-9]+\\)$" in
  if (string_match r_1 s 0) then (solve_1 (Str.matched_group 1 s) (Str.matched_group 2 s))
  else if string_match r_2 s 0 then solve_2 (Str.matched_group 2 s) (Str.matched_group 1 s)
  else raise (Failure "Unknown format");;

let rec iter i max =
  if i < max then
    let s = input_line stdin in
    (print_string (solve s); print_newline (); iter (succ i) max)in
iter 0 (int_of_string (input_line stdin));;

let get_int () =
let n = ref 0 in
let c = ref(input_char(stdin)) in
try
while !c >= '0' && !c <= '9' do
    n := !n * 10 + (int_of_char !c - int_of_char '0');
    c := input_char(stdin)
done;
n;
with End_of_file -> n;;

let int_of_column_header str =
let n = ref 0 in
let i = ref 0 in
try
while str.[!i] >= 'A' && str.[!i] <= 'Z' do
    n := !n * 26 + (int_of_char str.[!i] - int_of_char 'A' + 1);
    i := !i + 1
done;
(!n,!i);
with End_of_file -> (!n,!i);;

let column_header_of_int n =
 let s = ref "" in
 let nref = ref n in
 while !nref > 0 do
  s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;
  nref := (!nref-1)/26;
 done;
 !s;;

let n = get_int() in

while !n > 0 do

let str = read_line() in
let cindex = try String.index str 'C' with Not_found -> -1 in
let alt_form = if str.[0] = 'R' && (str.[1] >= '0' && str.[1] <= '9') && (cindex >= 0) then column_header_of_int(int_of_string(String.sub str (cindex + 1) (String.length str - cindex - 1))) ^ (String.sub str 1 (cindex - 1)) else let (n,i) = int_of_column_header str in "R" ^ (String.sub str i (String.length str - i)) ^ "C" ^ string_of_int n in
print_endline(alt_form);

n := !n - 1

done;;

let rc_format coordinate =
  let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in
  if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then
	(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))
  else
	(false, -1, -1)

let excel_format coordinate =
  let rec decode_column c pos =
	if coordinate.[pos] < 'A' then
	  (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)
	else
	  decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)
  in
  decode_column 0 0

let to_excel_format r c =
  let rec encode_column c =
	if c > 0 then
	  (encode_column ((c - 1) / 26)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + ((c - 1) mod 26))))
	else
	  ""
  in
  (encode_column c) ^ (string_of_int r)

let to_rc_format r c =
  "R" ^ (string_of_int r) ^ "C" ^ (string_of_int c)

let () =
  for n = read_int () downto 1 do
	let coordinate = read_line () in
	let (is_rc_format, x, y) = rc_format coordinate in
	if is_rc_format then
	  Printf.printf "%s" (to_excel_format x y)
	else (
	  (* Printf.printf "hooray!!!"; *)
	  let (x, y) = excel_format coordinate in
	  Printf.printf "%s" (to_rc_format x y)
	);
	print_newline()
  done

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc last_div n =
    if n <= 26
    then (
      if not last_div && ((String.length acc > 0) && ((String.get acc 0) = 'Z')) && (char_at_pos ((n-1) mod 26)) == 'Z'
      then acc
      else if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else
      if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
      else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
  in aux "" false col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

let ia = int_of_char 'A' in
let isrc str =
    if str.[0] <> 'R' then failwith "Wrong"
    else let p = String.index_from str 2 'C' in (true, int_of_string (String.sub str (p + 1) (String.length str - p - 1)), int_of_string (String.sub str 1 (p - 1)))
and isan str =
    let rec strip_al ald pos =
    if str.[pos] < 'A' then (ald, pos) else strip_al (26 * ald + (int_of_char str.[pos] - ia + 1)) (pos + 1)
    in
    let (ra, rp) = strip_al 0 0
    in
    (false, ra, int_of_string (String.sub str rp (String.length str - rp)))
and oprc y x =
    print_char 'R'; print_int x; print_char 'C'; print_int y
and opan x y =
    let rec px x = if x > 0 then let _ = px ((x - 1) / 26) in print_char (char_of_int ((x - 1) mod 26 + ia)) else () in
    px x; print_int y
in
for lc = (read_int ()) downto 1 do
    let line = read_line () in
        let (is_rc, x, y) = try isrc line with _ -> isan line in
        (if is_rc then opan else oprc) x y; print_newline ()
done

let read_line_of_strings () =
  read_line () |> Str.split (Str.regexp " +")

let read_line_of f =
  read_line_of_strings () |> List.map f

let read_line_of_floats () =
  read_line_of float_of_string

let coordinates_of_string input =
  let rx1 = Str.regexp "^R\\([0-9]+\\)C\\([0-9]+\\)$" in
  let rx2 = Str.regexp "^\\([A-Z]+\\)\\([0-9]+\\)$" in
  if Str.string_match rx1 input 0 then
    let row = Str.matched_group 1 input in
    let col = Str.matched_group 2 input in
    `RC (int_of_string row, int_of_string col)
  else if Str.string_match rx2 input 0 then
    let col = Str.matched_group 1 input in
    let row = Str.matched_group 2 input in
    `A1 (int_of_string row, col)
  else
    raise (Invalid_argument input)

let name_to_int name =
  let len = String.length name in
  let sum = ref 0 in
  let acc = ref 1 in
  for i = len - 1 downto 0 do
    sum := !sum + (Char.code name.[i] - 64) * !acc;
    acc := !acc * 26;
  done;
  !sum

let to_char k =
  String.make 1 (Char.chr k)

let int_to_name n =
  let rec iter dividend name =
    if dividend > 0 then
      let modulo = (dividend - 1) mod 26 in
      let next_char = to_char (65 + modulo) in
      iter ((dividend - modulo) / 26) (next_char ^ name)
    else
      name
  in
  iter n ""

let solve = function
  | `RC (row, col) -> Printf.sprintf "%s%d" (int_to_name col) row
  | `A1 (row, col) -> Printf.sprintf "R%dC%d" row (name_to_int col)

let convert input =
  solve (coordinates_of_string input)

let () =
  let [count] = read_line_of int_of_string in
  for i = 1 to count do
    read_line_of coordinates_of_string
    |> List.iter (fun task -> Printf.printf "%s\n" (solve task))
  done;

let rec base_26 a =
  if a = 0 then []
  else (a mod 26) :: (base_26 (a / 26))

let inv26 a =
  let n = String.length a in
  let r = ref 0 in
  for i = 0 to (n-1) do
    r := !r * 26 + (Char.code a.[i] - 64)
  done;
  !r

let rec implode lc =
  match lc with
  |[] -> ""
  |c::t -> Printf.sprintf "%c%s" c (implode t)

let convert_nb n =
  let n = int_of_string n in
  let l = if n = 1 then [0] else (base_26 (n - 1)) in
  let l = List.rev ((List.hd l + 1) :: (List.tl l)) in
  implode (List.map (fun n -> Char.chr (n + 64)) l)

let () =
  let s = read_line () in
  let n = int_of_string s in
  for i = 0 to (n-1) do
    let s = read_line () in
    if Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0 then begin
      let s = String.sub s 1 (String.length s - 1) in
      let [a;b] = Str.split (Str.regexp "C") s in
      Printf.printf "%s%s\n" (convert_nb b) a
    end else begin
      ignore (Str.search_forward (Str.regexp "[A-Z]+") s 0);
      let a = Str.matched_string s in
      ignore (Str.search_forward (Str.regexp "[0-9]+") s 0);
      let b = Str.matched_string s in
      Printf.printf "R%sC%i\n" b (inv26 a)
    end
  done;

let rec base_26 a =
  if a <= 0 then []
  else (a mod 26) :: (base_26 (a / 26 - 1))

let inv26 a =
  let n = String.length a in
  let r = ref 0 in
  for i = 0 to (n-1) do
    r := !r * 26 + (Char.code a.[i] - 64)
  done;
  !r

let rec implode lc =
  match lc with
  |[] -> ""
  |c::t -> Printf.sprintf "%c%s" c (implode t)

let convert_nb n =
  let n = int_of_string n in
  let l = if n = 1 then [0] else List.rev (base_26 (n - 1)) in
  implode (List.map (fun n -> Char.chr (n + 65)) l)

let () =
  let s = read_line () in
  let n = int_of_string s in
  for i = 0 to (n-1) do
    let s = read_line () in
    if Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0 then begin
      let s = String.sub s 1 (String.length s - 1) in
      let [a;b] = Str.split (Str.regexp "C") s in
      Printf.printf "%s%s\n" (convert_nb b) a
    end else begin
      ignore (Str.search_forward (Str.regexp "[A-Z]+") s 0);
      let a = Str.matched_string s in
      ignore (Str.search_forward (Str.regexp "[0-9]+") s 0);
      let b = Str.matched_string s in
      Printf.printf "R%sC%i\n" b (inv26 a)
    end
  done;

open Printf
open Scanf

type coord =
  | RC of int * int (* row, column *)
  | Concat of string * int (* column, row *)

let parse: string -> coord =
  fun s ->
  if (Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0) then
    let sep = Str.search_forward (Str.regexp "C[0-9]+") s 0 in
    let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in
    let b = int_of_string (Str.string_after s (sep + 1)) in
    RC (a, b)
  else
    let sep = Str.search_forward (Str.regexp "[0-9]+") s 0 in
    let a = Str.string_before s sep in
    let b = int_of_string (Str.string_after s sep) in
    Concat (a, b)

let pp: coord -> string =
  fun c ->
  match c with
  | RC(a, b) -> "R" ^ (string_of_int a) ^ "C" ^ (string_of_int b)
  | Concat(a, b) -> a ^ (string_of_int b)

let translate: coord -> coord =
  let char_to_num c = (Char.code c) - (Char.code 'A') + 1in
  let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in
  let num_to_str_system n =
    let rec inner i s =
      let d = i / 26
      and r = i mod 26 in
      if d > 0 then
        if r = 0 then
          inner (d - 1) ((String.make 1 'Z') ^ s)
        else
          inner d ((String.make 1 (num_to_char r)) ^ s)
      else
        (String.make 1 (num_to_char r)) ^ s
    in
    inner n ""
  in
  let str_to_num_system s =
    let rec inner s =
      if (String.length s > 1) then
        (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))
      else
        (char_to_num s.[String.length s - 1])
    in
    inner s
  in
  fun c ->
  match c with
  | RC(a, b) -> Concat(num_to_str_system b, a)
  | Concat(a, b) -> RC(b, str_to_num_system a)

let main () =
  let input = input_line stdin in
  let n = sscanf input "%i" (fun x -> x) in
  for i = 1 to n do
    let input = input_line stdin in
    let s = sscanf input "%s" (fun x -> x) in
    let c = parse s in
    let t = translate c in
    printf "%s\n" (pp t);
  done

let _ = main ()

open Printf
open Scanf

type coord =
  | RC of int * int (* row, column *)
  | Concat of string * int (* column, row *)

let parse: string -> coord =
  fun s ->
  if (Str.string_match (Str.regexp "R[0-9]+C[0-9]+") s 0) then
    let sep = Str.search_forward (Str.regexp "C[0-9]+") s 0 in
    let a = int_of_string (Str.string_after (Str.string_before s sep) 1) in
    let b = int_of_string (Str.string_after s (sep + 1)) in
    RC (a, b)
  else
    let sep = Str.search_forward (Str.regexp "[0-9]+") s 0 in
    let a = Str.string_before s sep in
    let b = int_of_string (Str.string_after s sep) in
    Concat (a, b)

let pp: coord -> string =
  fun c ->
  match c with
  | RC(a, b) -> "R" ^ (string_of_int a) ^ "C" ^ (string_of_int b)
  | Concat(a, b) -> a ^ (string_of_int b)

let translate: coord -> coord =
  let char_to_num c = (Char.code c) - (Char.code 'A') + 1in
  let num_to_char n = Char.chr ((Char.code 'A') - 1 + n) in
  let num_to_str_system n =
    let rec inner i s =
      let d = i / 26
      and r = i mod 26 in
      if d > 0 then
        inner d ((String.make 1 (num_to_char r)) ^ s)
      else
        (String.make 1 (num_to_char r)) ^ s

    in
    inner n ""
  in
  let str_to_num_system s =
    let rec inner s =
      if (String.length s > 1) then
        (char_to_num s.[String.length s - 1]) + 26 * (inner (Str.string_before s (String.length s - 1)))
      else
        (char_to_num s.[String.length s - 1])
    in
    inner s
  in
  fun c ->
  match c with
  | RC(a, b) -> Concat(num_to_str_system b, a)
  | Concat(a, b) -> RC(b, str_to_num_system a)

let main () =
  let input = input_line stdin in
  let n = sscanf input "%i" (fun x -> x) in
  for i = 1 to n do
    let input = input_line stdin in
    let s = sscanf input "%s" (fun x -> x) in
    let c = parse s in
    let t = translate c in
    printf "%s\n" (pp t);
  done

let _ = main ()

let n = read_int () ;;
let r = Str.regexp "R[0-9]+C[0-9]+" ;;
for i = 1 to n do
       let coord = read_line () in
       let is_first = Str.string_match r coord 0 in
       if is_first then begin
               let coords = Str.split (Str.regexp "[A-Z]") coord in
               let col = int_of_string (List.nth coords 0) in
               let row = int_of_string (List.nth coords 1) in
               let buf1 = Buffer.create 1000 in
               let rec rstring num buf =
                       let r = num mod 26 in
                       if (num/26) = 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               Buffer.contents buf
                       end
                       else if r != 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               rstring (num/26) buf
                       end
                       else if ((num-1)/26) != 0 then begin
                           let _ = Buffer.add_char buf 'Z' in
                           rstring ((num-1)/26) buf
                       end
                       else begin
                               let _ = Buffer.add_char buf 'Z' in
                               Buffer.contents buf
       end in

               let rec rev s =
                       let sl = String.length s in
                       for j=0 to (sl-1)/2 do
                               let c = s.[j] in
                               s.[j] <- s.[sl-j-1];
                               s.[sl-j-1] <- c;
                       done;
                       s in
               let row_s = rev (rstring (row) (Buffer.create 2)) in
               let _ = Printf.printf "%s%d\n" row_s col in

               row
       end
       else begin
               let rec row str j =
                       let fchar = Char.code str.[j] in
                       let schar = Char.code str.[j+1] in
                       if schar >= 65 then
                               26*(fchar-64) + (row str (j+1))
                       else
                               fchar - 64 in
               let rnum = row coord 0 in
               let cpos = Str.search_forward (Str.regexp "[0-9]+") coord 0 in
               (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in
               *)
               let cstring = Str.matched_string coord in
               let cint = int_of_string cstring in
               let _ = Printf.printf "R%dC%d\n" cint rnum in
               1
       end
done;

let n = read_int () ;;
let r = Str.regexp "R[0-9]+C[0-9]+" ;;
for i = 1 to n do
       let coord = read_line () in
       let is_first = Str.string_match r coord 0 in
       if is_first then begin
               let coords = Str.split (Str.regexp "[A-Z]") coord in
               let row = int_of_string (List.nth coords 0) in
               let col = int_of_string (List.nth coords 1) in
               let buf1 = Buffer.create 1000 in
               let rec rstring num buf =
                       let r = num mod 26 in
                       if (num/26) = 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               Buffer.contents buf
                       end
                       else if r != 0 then begin
                               let _ = Buffer.add_char buf (Char.chr (r+64)) in
                               rstring (num/26) buf
                       end
                       else if ((num-1)/26) != 0 then begin
                           let _ = Buffer.add_char buf 'Z' in
                           rstring ((num-1)/26) buf
                       end
                       else begin
                               let _ = Buffer.add_char buf 'Z' in
                               Buffer.contents buf
       end in

               let rec rev s =
                       let sl = String.length s in
                       for j=0 to (sl-1)/2 do
                               let c = s.[j] in
                               s.[j] <- s.[sl-j-1];
                               s.[sl-j-1] <- c;
                       done;
                       s in
               let row_s = rev (rstring (row) (Buffer.create 2)) in
               let _ = Printf.printf "%s%d\n" row_s col in

               row
       end
       else begin
               let rec row str j =
                       let fchar = Char.code str.[j] in
                       let schar = Char.code str.[j+1] in
                       if schar >= 65 then
                               26*(fchar-64) + (row str (j+1))
                       else
                               fchar - 64 in
               let rnum = row coord 0 in
               let cpos = Str.search_forward (Str.regexp "[0-9]+") coord 0 in
               (*let cstring = String.sub coord cpos ((String.length coord)-cpos) in
               *)
               let cstring = Str.matched_string coord in
               let cint = int_of_string cstring in
               let _ = Printf.printf "R%dC%d\n" rnum cint in
               1
       end
done;

open Scanf;;
open Num;;
open Printf;;
open String;;

exception No_num;;
exception Digit;;

type cell = RC | NRC;;

let print_cell t = match t with
    RC -> print_endline "RC"
   |NRC -> print_endline "NRC"

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;

let myindex s c = try index s c with Not_found -> -100;;

let ntostring=[|"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z"|];;

let is_digit = function
  |'1' | '2' |'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' -> true
  |_ -> false;;

let rec process t s = match t with
    RC -> process_RC s
   |NRC -> process_NRC s
and process_RC x =
  let (rown,coln) = get_num x in
    print_string (convert_to_AB coln); print_int rown; print_endline "";
and get_num x = let m = index x 'C' in
		(int_of_string (sub x 1 (m-1)),
		 int_of_string (sub x (m+1) ( (length x) - m -1)))
and convert_to_AB x =
  let y = ref x in
  let ss = ref "" in
  let () =
    while !y > 0  do
      let tmp = ((!y-1) mod 26) in
      y := !y / 26;
      ss := ntostring.(tmp) ^ !ss
    done in !ss
and process_NRC x =
  let (ab,row) = get_content x in
  print_char 'R'; print_int row; print_char 'C'; print_int (convert_to_int ab);
  print_endline "";
and get_content x = let m = digit_index x in
		    (sub x 0 m, int_of_string (sub x m ((length x)-m)))
and convert_to_int x =
  let k = ref ((length x) - 1) in
  let mul = ref 1 in
  let acc = ref 0 in
  let nA = int_of_char 'A' in
  let () =
    while !k >=0 do
      let f = get x !k in
      let g = (int_of_char f) - nA + 1 in
      acc := !acc + g*(!mul); mul:= !mul*26; k:=!k-1
    done in !acc

and digit_index x =
  let k = ref 0 in
  try
    let () =
      for i = 0 to ((length x) - 1)
      do
	let f =  get x i in
	if is_digit f then
	  raise Digit
	else k:=!k+1
      done in !k
  with Digit -> !k
;;

  for i=1 to n do
    let s = Scanf.bscanf Scanf.Scanning.stdin "%s " (fun x -> x) in
    let t = match (myindex s 'R', myindex s 'C')  with
      | (-100, _) -> NRC
      | (_,-100) -> NRC
      | (a, b)  -> if  b - a > 1 then RC else NRC
    in process t s
  done;;

open Scanf;;
open Num;;
open Printf;;
open String;;

exception No_num;;
exception Digit;;

type cell = RC | NRC;;

let print_cell t = match t with
    RC -> print_endline "RC"
   |NRC -> print_endline "NRC"

let n = Scanf.bscanf Scanf.Scanning.stdin "%d " (fun x -> x);;

let myindex s c = try index s c with Not_found -> -100;;

let ntostring=[|"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z"|];;

let is_digit = function
  |'1' | '2' |'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' -> true
  |_ -> false;;

let rec process t s = match t with
    RC -> process_RC s
   |NRC -> process_NRC s
and process_RC x =
  let (rown,coln) = get_num x in
    print_string (convert_to_AB coln); print_int rown; print_endline "";
and get_num x = let m = index x 'C' in
		(int_of_string (sub x 1 (m-1)),
		 int_of_string (sub x (m+1) ( (length x) - m -1)))
and convert_to_AB x =
  let y = ref x in
  let ss = ref "" in
  let () =
    while !y > 0  do
      let tmp = ((!y-1) mod 26) in
      y := (!y - tmp - 1) / 26;
      ss := ntostring.(tmp) ^ !ss
    done in !ss
and process_NRC x =
  let (ab,row) = get_content x in
  print_char 'R'; print_int row; print_char 'C'; print_int (convert_to_int ab);
  print_endline "";
and get_content x = let m = digit_index x in
		    (sub x 0 m, int_of_string (sub x m ((length x)-m)))
and convert_to_int x =
  let k = ref ((length x) - 1) in
  let mul = ref 1 in
  let acc = ref 0 in
  let nA = int_of_char 'A' in
  let () =
    while !k >=0 do
      let f = get x !k in
      let g = (int_of_char f) - nA + 1 in
      acc := !acc + g*(!mul); mul:= !mul*26; k:=!k-1
    done in !acc

and digit_index x =
  let k = ref 0 in
  try
    let () =
      for i = 0 to ((length x) - 1)
      do
	let f =  get x i in
	if is_digit f then
	  raise Digit
	else k:=!k+1
      done in !k
  with Digit -> !k
;;

  for i=1 to n do
    let s = Scanf.bscanf Scanf.Scanning.stdin "%s " (fun x -> x) in
    let t = match (myindex s 'R', myindex s 'C')  with
      | (-100, _) -> NRC
      | (_,-100) -> NRC
      | (a, b)  -> if  b - a > 1 then RC else NRC
    in print_string s; print_string " :  "; process t s
  done;;

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
      beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0)  then
    (int_of_string one):: (returnIntList t "")
      else returnIntList t (one^h)
  | _ -> (int_of_string one)::[]

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let checkIsRC str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "R" == 0)
    then true
    else false

let rec reverseList li o =
  match li with
  | [] -> o
  | h :: t -> reverseList t (h :: o)

let returnConvertedCol k =
  let rec returnIt s =
    if (s > 0) then
      let n = s / 26 in
      let r = s mod 26 in
      (string_of_int r) :: returnIt n
    else [] in
  reverseList (returnIt (int_of_string k)) []

let returnConvertedRow n =
  let rec returnIt s =
    let k = s mod 10 in
    if (s > 0) then
      (Char.chr (k+64)) :: (returnIt (s/10))
    else
      [] in
  reverseList (returnIt (int_of_string n)) []

let rec printList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_string h; printList t

let rec printCharList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_char h; printCharList t

let changeRCToAlph line =
  let rec newline l row col=
    if (compare (String.sub l 0 1) "C") == 0 then
      (row, String.sub l 1 (String.length l -1))
    else
      let newRow = row ^ (String.sub l 0 1) in
      newline (String.sub l 1 (String.length l -1))
      newRow col in
  let (r,c) = newline line "" ""  in
  let rList = returnConvertedRow r in
  let cList = returnConvertedCol c in
  printCharList rList; printList cList; print_string "\n"

let changeNumToAscii n =
  let num = int_of_string n in
  let rec returnNum k =
    let s = k/10 in
    let r = k mod 10 in
    if (s > 0) then
      r + 26*(returnNum s)
    else
      r in
  string_of_int (returnNum num)

let changeAlphToRC line =
  let rec newline l row =
    if Char.code(String.get l 0) < 65 then
    (row, l)
    else
      let c = (Char.chr(Char.code(String.get l 0)-16)) in
    newline (String.sub l 1 (String.length l -1)) (row^(Char.escaped c)) in
  let (r,c) = newline line "" in
  print_char 'R';print_string r;print_char 'C';
  print_string(changeNumToAscii c)

let n = read_int()

let check line =
  if (checkIsRC line) then
    changeRCToAlph(String.sub line 1 (String.length line -1))
  else
    changeAlphToRC line

let rec strList num =
  if (num > 0) then
    let k = read_line() in
    let _ = check k in
    strList (num-1)
  else
    print_string""
let _ = strList n

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
      beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0)  then
    (int_of_string one):: (returnIntList t "")
      else returnIntList t (one^h)
  | _ -> (int_of_string one)::[]

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec checkInCHere str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "C" == 0)
      then true
    else if (int_of_string (String.sub str 0 1)) <= 9 && (int_of_string(String.sub str 0 1)) >= 0 then checkInCHere (String.sub str 1 (String.length str - 1))
    else false

let checkIsRC str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "R" == 0)
    then checkInCHere (String.sub str 1 (String.length str - 1))
    else false

let rec reverseList li o =
  match li with
  | [] -> o
  | h :: t -> reverseList t (h :: o)

let returnConvertedCol k =
  let rec returnIt s =
    if (s > 0) then
      let n = s / 26 in
      let r = s mod 26 in
      (string_of_int r) :: returnIt n
    else [] in
  reverseList (returnIt (int_of_string k)) []

let returnConvertedRow n =
  let rec returnIt s =
    let k = s mod 26 in
    if (s > 0) then
      (Char.chr (k+64)) :: (returnIt (s/26))
    else
      [] in
  reverseList (returnIt (int_of_string n)) []

let rec printList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_string h; printList t

let rec printCharList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_char h; printCharList t

let changeRCToAlph line =
  let rec newline l row col=
    if (compare (String.sub l 0 1) "C") == 0 then
      (row, String.sub l 1 (String.length l -1))
    else
      let newRow = row ^ (String.sub l 0 1) in
      newline (String.sub l 1 (String.length l -1))
      newRow col in
  let (r,c) = newline line "" ""  in
  let rList = returnConvertedRow c in
  let cList = returnConvertedCol r in
  printCharList rList; printList cList; print_string "\n"

let changeStringToAscii n =
  let rec returnStringToNum str num =
    match str with
    | "" -> num
    | s ->
      returnStringToNum (String.sub s 1 (String.length str - 1))
      ((Char.code(String.get s 0) - 64) + 26*num) in
  string_of_int (returnStringToNum n 0)

let changeAlphToRC line =
  let rec newline l row =
    if Char.code(String.get l 0) < 65 then
    (row, l)
    else
    newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in
  let (r,c) = newline line "" in
  print_char 'R';print_string c;print_char 'C';
  print_string(changeStringToAscii r);print_string"\n"

let n = read_int()

let check line =
  if (checkIsRC line) then
    changeRCToAlph(String.sub line 1 (String.length line -1))
  else
    changeAlphToRC line

let rec strList num =
  if (num > 0) then
    let k = read_line() in
    let _ = check k in
    strList (num-1)
  else
    print_string""
let _ = strList n

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
      beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0)  then
    (int_of_string one):: (returnIntList t "")
      else returnIntList t (one^h)
  | _ -> (int_of_string one)::[]

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let checkIsRC str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "R" == 0)
    then true
    else false

let rec reverseList li o =
  match li with
  | [] -> o
  | h :: t -> reverseList t (h :: o)

let returnConvertedCol k =
  let rec returnIt s =
    if (s > 0) then
      let n = s / 26 in
      let r = s mod 26 in
      (string_of_int r) :: returnIt n
    else [] in
  reverseList (returnIt (int_of_string k)) []

let returnConvertedRow n =
  let rec returnIt s =
    let k = s mod 10 in
    if (s > 0) then
      (Char.chr (k+64)) :: (returnIt (s/10))
    else
      Char.chr(s) :: [] in
  reverseList (returnIt (int_of_string n)) []

let rec printList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_string h; printList t

let rec printCharList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_char h; printCharList t

let changeRCToAlph line =
  let rec newline l row col=
    if (compare (String.sub l 0 1) "C") == 0 then
      (row, String.sub l 1 (String.length l -1))
    else
      let newRow = row ^ (String.sub l 0 1) in
      newline (String.sub l 1 (String.length l -1))
      newRow col in
  let (r,c) = newline line "" ""  in
  let rList = returnConvertedRow r in
  let cList = returnConvertedCol c in
  printCharList rList; printList cList; print_string "\n"

let changeNumToAscii n =
  let num = int_of_string n in
  let rec returnNum k =
    let s = k/10 in
    let r = k mod 10 in
    if (s > 0) then
      r + 26*(returnNum s)
    else
      r in
  string_of_int (returnNum num)

let changeAlphToRC line =
  let rec newline l row =
    if Char.code(String.get l 0) < 65 then
    (row, l)
    else
      let c = (Char.chr(Char.code(String.get l 0)-16)) in
    newline (String.sub l 1 (String.length l -1)) (row^(Char.escaped c)) in
  let (r,c) = newline line "" in
  print_char 'R';print_string r;print_char 'C';
  print_string(changeNumToAscii c)

let n = read_int()

let check line =
  if (checkIsRC line) then
    changeRCToAlph(String.sub line 1 (String.length line -1))
  else
    changeAlphToRC line

let rec strList num =
  if (num > 0) then
    let k = read_line() in
    let _ = check k in
    strList (num-1)
  else
    print_string""
let _ = strList n

let rec split num str =
  match str with
  | "" -> []
  | s ->
    let (beg, rest) = (String.sub str 0 num, String.sub str num(String.length str - num)) in
      beg :: (split num rest)

let rec returnIntList strList one =
  match strList with
  | h :: t -> if (compare h " " == 0 || compare h "\n" == 0)  then
    (int_of_string one):: (returnIntList t "")
      else returnIntList t (one^h)
  | _ -> (int_of_string one)::[]

let splitToList line =
  let lineList = split 1 line in
  returnIntList lineList ""

let rec checkInCHere str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "C" == 0)
      then true
    else if (int_of_string (String.sub str 0 1)) <= 9 && (int_of_string(String.sub str 0 1)) >= 0 then checkInCHere (String.sub str 1 (String.length str - 1))
    else false

let checkIsRC str =
  match str with
  | "" -> false
  | s ->
    if (compare (String.sub str 0 1) "R" == 0)
    then checkInCHere (String.sub str 2 (String.length str - 2))
    else false

let rec reverseList li o =
  match li with
  | [] -> o
  | h :: t -> reverseList t (h :: o)

let returnConvertedCol k =
  let rec returnIt s =
    if (s > 0) then
      let n = s / 26 in
      let r = s mod 26 in
      (string_of_int r) :: returnIt n
    else [] in
  reverseList (returnIt (int_of_string k)) []

let returnConvertedRow n =
  let rec returnIt s =
    let k = s mod 26 in
    if (s > 0) then
      (Char.chr (k+64)) :: (returnIt (s/26))
    else
      [] in
  reverseList (returnIt (int_of_string n)) []

let rec printList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_string h; printList t

let rec printCharList li =
  match li with
  | [] -> print_string ""
  | h :: t -> print_char h; printCharList t

let changeRCToAlph line =
  let rec newline l row col=
    if (compare (String.sub l 0 1) "C") == 0 then
      (row, String.sub l 1 (String.length l -1))
    else
      let newRow = row ^ (String.sub l 0 1) in
      newline (String.sub l 1 (String.length l -1))
      newRow col in
  let (r,c) = newline line "" ""  in
  let rList = returnConvertedRow c in
  printCharList rList; print_string r; print_string "\n"

let changeStringToAscii n =
  let rec returnStringToNum str num =
    match str with
    | "" -> num
    | s ->
      returnStringToNum (String.sub s 1 (String.length str - 1))
      ((Char.code(String.get s 0) - 64) + 26*num) in
  string_of_int (returnStringToNum n 0)

let changeAlphToRC line =
  let rec newline l row =
    if Char.code(String.get l 0) < 65 then
    (row, l)
    else
    newline (String.sub l 1 (String.length l -1)) (row^(String.sub l 0 1)) in
  let (r,c) = newline line "" in
  print_char 'R';print_string c;print_char 'C';
  print_string(changeStringToAscii r);print_string"\n"

let n = read_int()

let check line =
  if (checkIsRC line) then
    changeRCToAlph(String.sub line 1 (String.length line -1))
  else
    changeAlphToRC line

let rec strList num =
  if (num > 0) then
    let k = read_line() in
    let _ = check k in
    strList (num-1)
  else
    print_string""
let _ = strList n

let get_int c =
let n = ref 0 in
try
while !c >= '0' && !c <= '9' do
    n := !n * 10 + (int_of_char !c - int_of_char '0');
    c := input_char(stdin)
done;
(n,c);
with End_of_file -> (n,c);;

let n = fst(get_int(ref '0')) in
while !n > 0 do

let firstchar = input_char(stdin) in
let secondchar = input_char(stdin) in

let int_of_column_header (fc,sc) =
let n = ref 0 in
(n := !n * 26 + (int_of_char !fc - int_of_char 'A' + 1);
try
while !sc >= 'A' && !sc <= 'Z' do
    n := !n * 26 + (int_of_char !sc - int_of_char 'A' + 1);
    sc := input_char(stdin)
done;
(n,sc);
with End_of_file -> (n,sc)) in

let column_header_of_int n =
 let s = ref "" in
 let nref = ref n in
 while !nref > 0 do
  s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;
  nref := (!nref-1)/26;
 done;
 !s in

let row_first c = let row = !(fst(get_int(c))) in let column = !(fst(get_int(ref '0'))) in (row,column) in

let column_first (fc, sc) = let nc = int_of_column_header(fc,sc) in let column = !(fst(nc)) in let row = !(fst(get_int(snd(nc)))) in (row,column) in

let rc = if firstchar = 'R' && (secondchar >= '0' && secondchar <= '9') then row_first (ref secondchar) else column_first(ref firstchar, ref secondchar) in

let alt_format = if firstchar = 'R' && (secondchar >= '0' && secondchar <= '9') then column_header_of_int(snd(rc)) ^ string_of_int(fst(rc))
else "R" ^ string_of_int(fst(rc)) ^ "C" ^ string_of_int(snd(rc)) in

print_endline(alt_format);

n := !n - 1

done;;

let get_int c =
let n = ref 0 in
try
while !c >= '0' && !c <= '9' do
    n := !n * 10 + (int_of_char !c - int_of_char '0');
    c := input_char(stdin)
done;
(n,c);
with End_of_file -> (n,c);;

let n = fst(get_int(ref '0')) in
while !n > 0 do

let firstchar = input_char(stdin) in

let int_of_column_header c =
let n = ref 0 in
try
while !c >= 'A' && !c <= 'Z' do
    n := !n * 26 + (int_of_char !c - int_of_char 'A' + 1);
    c := input_char(stdin)
done;
(n,c);
with End_of_file -> (n,c) in

let column_header_of_int n =
 let s = ref "" in
 let nref = ref n in
 while !nref > 0 do
  s := Char.escaped(char_of_int((!nref-1) mod 26 + int_of_char 'A')) ^ !s;
  nref := !nref/26;
 done;
 !s in

let row_first c = let row = !(fst(get_int(c))) in let column = !(fst(get_int(ref '0'))) in (row,column) in

let column_first c = let nc = int_of_column_header(c) in let column = !(fst(nc)) in let row = !(fst(get_int(snd(nc)))) in (row,column) in

let rc = if firstchar = 'R' then let c = input_char(stdin) in row_first (ref c) else column_first(ref firstchar) in

let alt_format = if firstchar = 'R' then column_header_of_int(snd(rc)) ^ string_of_int(fst(rc))
else "R" ^ string_of_int(fst(rc)) ^ "C" ^ string_of_int(snd(rc)) in

print_endline(alt_format);

n := !n - 1

done;;

let rc_format coordinate =
  let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in
  if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then
	(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))
  else
	(false, -1, -1)

let excel_format coordinate =
  let rec decode_column c pos =
	if coordinate.[pos] < 'A' then
	  (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)
	else
	  decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)
  in
  decode_column 0 0

let to_excel_format r c =
  let rec encode_column c =
	if c > 0 then
	  (encode_column (c / 26)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + ((c - 1) mod 26))))
	else
	  ""
  in
  (encode_column c) ^ (string_of_int r)

let to_rc_format r c =
  "R" ^ (string_of_int r) ^ "C" ^ (string_of_int c)

let () =
  for n = read_int () downto 1 do
	let coordinate = read_line () in
	let (is_rc_format, x, y) = rc_format coordinate in
	if is_rc_format then
	  Printf.printf "%s" (to_excel_format x y)
	else (
	  (* Printf.printf "hooray!!!"; *)
	  let (x, y) = excel_format coordinate in
	  Printf.printf "%s" (to_rc_format x y)
	);
	print_newline()
  done

let rc_format coordinate =
  let pos = try String.index_from coordinate 2 'C' with Not_found -> -1 in
  if coordinate.[0] = 'R' && (coordinate.[1] >= '0' && coordinate.[1] <= '9') && (pos >= 2) then
	(true, int_of_string (String.sub coordinate 1 (pos - 1)), int_of_string (String.sub coordinate (pos + 1) (String.length coordinate - pos - 1)))
  else
	(false, -1, -1)

let excel_format coordinate =
  let rec decode_column c pos =
	if coordinate.[pos] < 'A' then
	  (int_of_string (String.sub coordinate pos ((String.length coordinate) - pos)), c)
	else
	  decode_column (c * 26 + (int_of_char coordinate.[pos]) - (int_of_char 'A') + 1) (pos + 1)
  in
  decode_column 0 0

let to_excel_format c r =
  let rec encode_column c =
	if c > 0 then
	  (encode_column (c / 26 - 1)) ^ (String.make 1 (char_of_int ((int_of_char 'A') + (c mod 26))))
	else
	  ""
  in
  (encode_column c) ^ (string_of_int r)

let to_rc_format r c =
  "R" ^ (string_of_int r) ^ "C" ^ (string_of_int c)

let () =
  for n = read_int () downto 1 do
	let coordinate = read_line () in
	let (is_rc_format, x, y) = rc_format coordinate in
	if is_rc_format then
	  Printf.printf "%s" (to_excel_format (y - 1) x)
	else (
	  (* Printf.printf "hooray!!!"; *)
	  let (x, y) = excel_format coordinate in
	  Printf.printf "%s" (to_rc_format x y)
	);
	print_newline()
  done

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc last_div n =
    if n <= 26
    then (
      if not last_div && ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then acc
      else if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else
      if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
      else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
  in aux "" false col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc last_div n =
    if n <= 26
    then (
      if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else
      if last_div || ((String.length acc > 0) && ((String.get acc 0) = 'Z'))
      then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
      else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
  in aux "" false col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc last_div n =
    if n <= 26
    then (
      if last_div
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else
      if last_div
      then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
      else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) ((n mod 26) = 0) (n / 26)
  in aux "" false col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> 0

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 26 -> 'Z' | _  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t ->
      aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let colum_number_to_string col =
  let rec aux acc n =
    if n <= 26
    then (Char.escaped (char_at_pos n)) ^ acc
    else aux (Char.escaped (char_at_pos (n mod 26)) ^ acc ) (n / 26)
  in aux "" col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (colum_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in
    List.rev (loop [] cnt)
  in
  List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc n =
    if n <= 26
    then (
      if (String.length acc > 0) && ((String.get acc 0) = 'Z')
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else
      if (String.length acc > 0) && ((String.get acc 0) = 'Z')
      then aux (String.make 1 (char_at_pos ((n-1) mod 26)) ^ acc ) (n / 26)
      else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) (n / 26)
  in aux "" col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

type numeration =
  | Excel of string * int
  | Coord of int * int

let string_to_numeration s =
  if Str.string_match (Str.regexp "^\\([A-Z]+\\)\\([1-9][0-9]*\\)$") s 0 then
    Some(Excel (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s)))
  else if Str.string_match (Str.regexp "^R\\([1-9][0-9]*\\)C\\([1-9][0-9]*\\)$") s 0 then
    Some(Coord (int_of_string (Str.matched_group 1 s), int_of_string (Str.matched_group 2 s)))
  else
    None

let string_to_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l)
  in exp (String.length s - 1) []

let pos_in_alphabet = function
  | 'A' -> 1  | 'B' -> 2  | 'C' -> 3  | 'D' -> 4  | 'E' -> 5
  | 'F' -> 6  | 'G' -> 7  | 'H' -> 8  | 'I' -> 9  | 'J' -> 10
  | 'K' -> 11 | 'L' -> 12 | 'M' -> 13 | 'N' -> 14 | 'O' -> 15
  | 'P' -> 16 | 'Q' -> 17 | 'R' -> 18 | 'S' -> 19 | 'T' -> 20
  | 'U' -> 21 | 'V' -> 22 | 'W' -> 23 | 'X' -> 24 | 'Y' -> 25
  | 'Z' -> 26 | _ -> -1;;

let char_at_pos = function
  | 1  -> 'A' | 2  -> 'B' | 3  -> 'C' | 4  -> 'D' | 5  -> 'E'
  | 6  -> 'F' | 7  -> 'G' | 8  -> 'H' | 9  -> 'I' | 10 -> 'J'
  | 11 -> 'K' | 12 -> 'L' | 13 -> 'M' | 14 -> 'N' | 15 -> 'O'
  | 16 -> 'P' | 17 -> 'Q' | 18 -> 'R' | 19 -> 'S' | 20 -> 'T'
  | 21 -> 'U' | 22 -> 'V' | 23 -> 'W' | 24 -> 'X' | 25 -> 'Y'
  | 0 -> 'Z' | x  -> ' '

let string_to_column_number s =
  let rec aux acc cur = function
    | [] -> acc
    | h :: t -> aux ((pos_in_alphabet h)*int_of_float(26. ** (float_of_int cur)) + acc) (cur+1) t
  in aux 0 0 (List.rev (string_to_list s))

let column_number_to_string col =
  let rec aux acc n =
    if n <= 26
    then (
      if acc = "Z"
      then (String.make 1 (char_at_pos ((n-1) mod 26))) ^ acc
      else (String.make 1 (char_at_pos (n mod 26))) ^ acc
    )
    else aux (String.make 1 (char_at_pos (n mod 26)) ^ acc ) (n / 26)
  in aux "" col

let numeration_to_string = function
  | Excel (col, row) -> col ^ (string_of_int row)
  | Coord (row, col) -> "R" ^ (string_of_int row) ^ "C" ^ (string_of_int col)

let switch_numeration = function
  | Excel (col, row) -> Coord (row, string_to_column_number(col))
  | Coord (row, col) -> Excel (column_number_to_string(col), row)

(*
let spreadsheets l =
  l
  |> List.map string_to_numeration
  |> List.filter (function Some(_) -> true | None -> false)
  |> List.map (function Some(x) -> x | x -> assert false)
  |> List.map switch_numeration
  |> List.map numeration_to_string
*)

let spreadsheets l =
  l
  |> List.map (fun x ->
      match string_to_numeration (x) with
      | Some(e) -> numeration_to_string (switch_numeration e)
      | None -> assert false)

let () =
  let num = read_int () in
  let do_parse cnt =
    let rec loop acc = function
      | c when c < 1 -> acc
      | c ->
        let s = Scanf.bscanf Scanf.Scanning.stdin "%s\n" (fun x -> x)
        in loop (s::acc) (c-1)
    in List.rev (loop [] cnt)
  in List.iter (Printf.printf "%s\n") (spreadsheets (do_parse num))

let ia = int_of_char 'A' in
let isrc str =
    if str.[0] <> 'R' then failwith "Wrong"
    else let p = String.index_from str 2 'C' in (true, int_of_string (String.sub str (p + 1) (String.length str - p - 1)), int_of_string (String.sub str 1 (p - 1)))
and isan str =
    let rec strip_al ald pos =
    if str.[pos] < 'A' then (ald, pos) else strip_al (26 * ald + (int_of_char str.[pos] - ia + 1)) (pos + 1)
    in
    let (ra, rp) = strip_al 0 0
    in
    (false, ra, int_of_string (String.sub str rp (String.length str - rp)))
and oprc y x =
    print_char 'R'; print_int x; print_char 'C'; print_int y
and opan x y =
    let rec px x = if x > 0 then let _ = px (x / 26) in print_char (char_of_int (x mod 26 - 1 + ia)) else () in
    px x; print_int y
in
for lc = (read_int ()) downto 1 do
    let line = read_line () in
        let (is_rc, x, y) = try isrc line with _ -> isan line in
        (if is_rc then opan else oprc) x y; print_newline ()
done

let read_line_of_strings () =
  read_line () |> Str.split (Str.regexp " +")

let read_line_of f =
  read_line_of_strings () |> List.map f

let read_line_of_floats () =
  read_line_of float_of_string

let coordinates_of_string input =
  let rx1 = Str.regexp "^R\\([0-9]+\\)C\\([0-9]+\\)$" in
  let rx2 = Str.regexp "^\\([A-Z]+\\)\\([0-9]+\\)$" in
  if Str.string_match rx1 input 0 then
    let row = Str.matched_group 1 input in
    let col = Str.matched_group 2 input in
    `RC (int_of_string row, int_of_string col)
  else if Str.string_match rx2 input 0 then
    let col = Str.matched_group 1 input in
    let row = Str.matched_group 2 input in
    `A1 (int_of_string row, col)
  else
    raise (Invalid_argument input)

let col_to_int name =
  let len = String.length name in
  let sum = ref 0 in
  let acc = ref 1 in
  for i = len - 1 downto 0 do
    sum := !sum + (Char.code name.[i] - 65) * !acc;
    acc := !acc * 26;
  done;
  !sum

let int_to_col n =
  let to_digit k = String.make 1 (Char.chr (k + 65)) in
  let rec iter name n =
    if n > 25 then
      let (d, n) = (n mod 26, n / 26) in
      iter (to_digit d ^ name) n
    else
      to_digit n ^ name
  in
  iter "" n

let solve = function
  | `RC (row, col) -> Printf.sprintf "%s%d" (int_to_col col) row
  | `A1 (row, col) -> Printf.sprintf "R%dC%d" row (col_to_int col)

let convert input =
  solve (coordinates_of_string input)

let () =
  let [count] = read_line_of int_of_string in
  for i = 1 to count do
    read_line_of coordinates_of_string
    |> List.iter (fun task -> Printf.printf "%s\n" (solve task))
  done;

let read_line_of_strings () =
  read_line () |> Str.split (Str.regexp " +")

let read_line_of f =
  read_line_of_strings () |> List.map f

let read_line_of_floats () =
  read_line_of float_of_string

let coordinates_of_string input =
  let rx1 = Str.regexp "^R\\([0-9]+\\)C\\([0-9]+\\)$" in
  let rx2 = Str.regexp "^\\([A-Z]+\\)\\([0-9]+\\)$" in
  if Str.string_match rx1 input 0 then
    let row = Str.matched_group 1 input in
    let col = Str.matched_group 2 input in
    `RC (int_of_string row, int_of_string col)
  else if Str.string_match rx2 input 0 then
    let col = Str.matched_group 1 input in
    let row = Str.matched_group 2 input in
    `A1 (int_of_string row, col)
  else
    raise (Invalid_argument input)

let col_to_int name =
  let len = String.length name in
  let sum = ref 0 in
  let acc = ref 1 in
  for i = len - 1 downto 0 do
    sum := !sum + (Char.code name.[i] - 64) * !acc;
    acc := !acc * 26;
  done;
  !sum

let int_to_col n =
  let to_digit k = String.make 1 (Char.chr (k + 64)) in
  let rec iter name n =
    if n > 26 then
      let (d, n) = (n mod 26, n / 26) in
      iter (to_digit d ^ name) n
    else
      to_digit n ^ name
  in
  iter "" n

let solve = function
  | `RC (row, col) -> Printf.sprintf "%s%d\n" (int_to_col col) row
  | `A1 (row, col) -> Printf.sprintf "R%dC%d\n" row (col_to_int col)

let () =
  let [count] = read_line_of int_of_string in
  for i = 1 to count do
    read_line_of coordinates_of_string
    |> List.iter (fun task -> Printf.printf "%s\n" (solve task))
  done;


Consider the set of all nonnegative integers: $$${0, 1, 2, \dots}$$$. Given two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$). We paint all the numbers in increasing number first we paint $$$0$$$, then we paint $$$1$$$, then $$$2$$$ and so on.Each number is painted white or black. We paint a number $$$i$$$ according to the following rules:    if $$$i = 0$$$, it is colored white;   if $$$i \ge a$$$ and $$$i - a$$$ is colored white, $$$i$$$ is also colored white;   if $$$i \ge b$$$ and $$$i - b$$$ is colored white, $$$i$$$ is also colored white;   if $$$i$$$ is still not colored white, it is colored black. In this way, each nonnegative integer gets one of two colors.For example, if $$$a=3$$$, $$$b=5$$$, then the colors of the numbers (in the order from $$$0$$$) are: white ($$$0$$$), black ($$$1$$$), black ($$$2$$$), white ($$$3$$$), black ($$$4$$$), white ($$$5$$$), white ($$$6$$$), black ($$$7$$$), white ($$$8$$$), white ($$$9$$$), ...Note that:    It is possible that there are infinitely many nonnegative integers colored black. For example, if $$$a = 10$$$ and $$$b = 10$$$, then only $$$0, 10, 20, 30$$$ and any other nonnegative integers that end in $$$0$$$ when written in base 10 are white. The other integers are colored black.   It is also possible that there are only finitely many nonnegative integers colored black. For example, when $$$a = 1$$$ and $$$b = 10$$$, then there is no nonnegative integer colored black at all. Your task is to determine whether or not the number of nonnegative integers colored black is infinite.If there are infinitely many nonnegative integers colored black, simply print a line containing "Infinite" (without the quotes). Otherwise, print "Finite" (without the quotes).

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ lines follow, each line contains two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$).

For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers).

open Printf
open Scanf
let read_int _ = bscanf Scanning.stdin " %d " (fun x -> x)
let rec gcd a b =
	if b = 0 then a
	else gcd b (a mod b)

let () =
	let n = read_int() in
	for i = 1 to n do
		let a = read_int() and b = read_int() in
		if gcd a b = 1 then printf "Finite\n"
		else printf "Infinite\n"
	done

let rec pgcd a b =
  if b = 0 then a
  else if a > b then
    pgcd b a
  else
    let r = b - a in
    pgcd a r

let _ =
  let n = int_of_string (input_line stdin) in
  for i = 1 to n do
    let l = List.map int_of_string @@ Str.split (Str.regexp " ") (input_line stdin) in
    let (a,b) =
      match l with
      | [a;b] -> (a,b)
      | _ -> assert false
    in
    if pgcd a b <> 1 then
      Format.printf "Infinite@."
    else
      Format.printf "Finite@."
  done