import Data.Char (ord, chr, isDigit)
import Data.Maybe (fromMaybe, isJust)
import Control.Monad (replicateM)

main :: IO ()
main = do
        ns <- getLine
        inputs <- replicateM (read ns) getLine
        mapM (putStrLn.reconvert) inputs
        return ()

data Position = Position Int Int deriving Show -- the reconvert :: String -> String
reconvert str = reconvert' (fromRC str) (fromBC str)

reconvert' :: (Maybe Position) -> (Maybe Position) -> String
reconvert' (Just pos1) _ = asXY pos1
reconvert' Nothing (Just pos2) = asRC pos2
reconvert' _ _ = "Eat shit"

fromRC :: String -> Maybe Position
fromRC str  | valid = Just $ Position (fromMaybe 0 r) (fromMaybe 0 c)
            | otherwise = Nothing
            where r = fromRCR str
                  c = fromRCC str
                  valid = isJust r && isJust c

fromRCR :: String -> Maybe Int
fromRCR ('R' : rs)  | length dig > 0 = Just (read dig)
                    | otherwise = Nothing
                    where dig = takeWhile isDigit rs
fromRCR _ = Nothing

fromRCC :: String -> Maybe Int
fromRCC ('R' : rs)  | length dig > 0 = Just (read dig)
                    | otherwise = Nothing
                    where dig = (takeWhile isDigit).(dropWhile (not.isDigit)).(dropWhile isDigit) $ rs
fromRCC _ = Nothing

fromBC :: String -> Maybe Position
fromBC str  | valid = Just $ Position (read rstr) (toInt (reverse cstr))
            | otherwise = Nothing
            where cstr = takeWhile (not.isDigit) str
                  rstr = (takeWhile isDigit).(dropWhile (not.isDigit)) $ str
                  valid = (length cstr) > 0 && (length rstr) > 0
                  toInt (c:cs) = (ord c - ord 'A' + 1) + 26 * (toInt cs)
                  toInt "" = 0

asRC :: Position -> String
asRC (Position row column) = "R" ++ (show row) ++ "C" ++ (show column)

asXY :: Position -> String
asXY (Position row column) = reverse (asBC column) ++ (show row)

asBC :: Int -> String
asBC val  | val > 0 = ch : (asBC dv)
          | otherwise = ""
          where dv = (val - 1) `div` 26
                md = val `mod` 26
                ch = if md == 0 then 'Z'
                                else chr (ord 'A' + md - 1)

import Control.Monad
import Data.Char
import Text.Parsec

main = do
  t <- read <$> getLine
  replicateM t routine

routine = do
  s <- getLine
  print $ trans $ parseCoord s

data Coord
  = Normal Int Int
  | Excel String Int

instance Show Coord where
  show (Normal r c) = 'R' : show r ++ 'C' : show c
  show (Excel c r) = c ++ show r

toLetters :: Int -> String
toLetters x
  | x <= 26 = [toLetter x]
  | otherwise = toLetters ((x - m) `div` 26) ++ toLetters m
  where
    toLetter x = chr (x + ord 'A' - 1)
    m = (x - 1) `mod` 26 + 1

toNumber :: String -> Int
toNumber [x] = ord x - ord 'A' + 1
toNumber xs = (toNumber $ init xs) * 26 + toNumber [last xs]

trans (Right (Normal r c)) = Excel (toLetters c) r
trans (Right (Excel c r)) = Normal r (toNumber c)

parseCoord = parse (try normalParser <|> excelParser) ""
  where
    normalParser = do
      char 'R'
      r <- read <$> many1 digit
      char 'C'
      c <- read <$> many1 digit
      return (Normal r c)
    excelParser = do
      c <- many1 upper
      r <- read <$> many1 digit
      return (Excel c r)

{-# OPTIONS_GHC -O2 #-}

import Data.Char

to26 :: Int -> [Char]
to26 n = helper n 26
  where
    helper n k | k >= n = to26' (n-1) k
    helper n k = helper (n - k) (k * 26)
    to26' n k
        | k == 1 = []
        | otherwise = chr (ord 'A' + div') : to26' mod' k'
          where
            k' = k `div` 26
            (div', mod') = divMod n k'

from26 :: [Char] -> Int
from26 s = from26' (reverse s) + 1 + sum [ 26^i | i <- [1..len-1]]
  where
    len = length s
    from26' [] = 0
    from26' (x:xs) = from26' xs * 26 + (ord x - ord 'A')

checkRC :: [Char] -> Bool
checkRC str = (head str == 'R') && (isDigit $ str !! 1) && (elem 'C' str)

rc2xy :: [Char] -> [Char]
rc2xy str = to26 c ++ show r
  where
    [r,c] = map read . words $ map (\ch -> if isDigit ch then ch else ' ') str

xy2rc :: [Char] -> [Char]
xy2rc str = "R" ++ y ++ "C" ++ show (from26 x)
  where
    (x,y) = span isUpper str

solve :: [Char] -> [Char]
solve str = if checkRC str then rc2xy str else xy2rc str

main = interact $ unlines . (\(n:b) -> map solve $ take (read n) b) . lines

import Data.List (groupBy)
import Data.Char (isUpper, isDigit, ord, chr)
import Data.Function (on)
import Control.Monad (replicateM_)

ordA :: Int
ordA = ord 'A'

atr :: String -> String -> String
atr s n = ("R" ++ n ++ "C" ++ show (foldl folder 0 s))
  where folder acc c = acc * 26 + ord c - ordA + 1

rta :: Int -> String -> String
rta a = (toa a "" ++)
  where
    toa x acc =
      if x == 0
      then acc
      else toa d (chr (ordA + m) : acc)
      where (d, m) = (x-1) `divMod` 26

solve :: String -> String
solve input =
  case groupBy ((==) `on` isDigit) input of
    [_, a, _, b] -> rta (read b) a
    [a, b] -> atr a b
{-
solve input =
  if null c
  then atr a (read b)
  else rta (read d) (read b)
  where
    (a, b') = span isUpper input
    (b, c') = span isDigit b'
    (c, d) = span isUpper c'
-}

main :: IO ()
main = do
  n' <- readLn
  replicateM_ n' (putStrLn . solve =<< getLine)

import Data.Char (isUpper, isDigit, ord, chr)
import Control.Monad (replicateM_)

ordA :: Int
ordA = ord 'A'

atr :: String -> Int -> String
atr s n = ("R" ++ show n ++ "C" ++ show (foldl folder 0 s))
  where folder acc c = acc * 26 + ord c - ordA + 1

rta :: Int -> Int -> String
rta a = (toa a "" ++) . show
  where
    toa x acc =
      if x == 0
      then acc
      else toa d (chr (ordA + m) : acc)
      where (d, m) = (x-1) `divMod` 26

solve :: String -> String
solve input =
  if null c
  then atr a (read b)
  else rta (read d) (read b)
  where
    (a, b') = span isUpper input
    (b, c') = span isDigit b'
    (c, d) = span isUpper c'

main :: IO ()
main = do
  n' <- readLn
  replicateM_ n' (putStrLn . solve =<< getLine)

import Data.List (groupBy)
import Data.Char (isUpper, isDigit, ord, chr)
import Data.Function (on)
import Control.Monad (replicateM_)

ordA :: Int
ordA = ord 'A'

atr :: String -> Int -> String
atr s n = ("R" ++ show n ++ "C" ++ show (foldl folder 0 s))
  where folder acc c = acc * 26 + ord c - ordA + 1

rta :: Int -> Int -> String
rta a = (toa a "" ++) . show
  where
    toa x acc =
      if x == 0
      then acc
      else toa d (chr (ordA + m) : acc)
      where (d, m) = (x-1) `divMod` 26

solve :: String -> String
solve input =
  case groupBy ((==) `on` isDigit) input of
    [_, a, _, b] -> rta (read b) (read a)
    [a, b] -> atr a (read b)
{-
solve input =
  if null c
  then atr a (read b)
  else rta (read d) (read b)
  where
    (a, b') = span isUpper input
    (b, c') = span isDigit b'
    (c, d) = span isUpper c'
-}

main :: IO ()
main = do
  n' <- readLn
  replicateM_ n' (putStrLn . solve =<< getLine)

import Data.List (groupBy)
import Data.Char (isUpper, isDigit, ord, chr)
import Data.Function (on)
import Control.Monad (replicateM_)

ordA :: Int
ordA = ord 'A'

atr :: String -> String -> String
atr s n = ("R" ++ n ++ "C" ++ show (foldl folder 0 s))
  where folder acc c = acc * 26 + ord c - ordA + 1

rta :: Int -> String -> String
rta a = (toa a "" ++)
  where
    toa 0 acc = acc
    toa x acc = toa d (chr (ordA + m) : acc)
      where (d, m) = (x-1) `divMod` 26

solve :: String -> String
solve input =
  case groupBy ((==) `on` isDigit) input of
    [_, a, _, b] -> rta (read b) a
    [a, b] -> atr a b

main :: IO ()
main = do
  n' <- readLn
  replicateM_ n' (putStrLn . solve =<< getLine)

import System.IO
import Data.Char (isUpper, isDigit, ord, chr)
import Control.Monad (replicateM_)

ordA :: Int
ordA = ord 'A'

atr :: String -> Int -> String
atr s n = ("R" ++ show n ++ "C" ++ show (foldl folder 0 s))
  where folder acc c = acc * 26 + ord c - ordA + 1

rta :: Int -> Int -> String
rta a = (toa a "" ++) . show
  where
    toa x acc =
      if x == 0
      then acc
      else toa d (chr (ordA + m) : acc)
      where (d, m) = (x-1) `divMod` 26

solve :: String -> String
solve input =
  if null c
  then atr a (read b)
  else rta (read d) (read b)
  where
    (a, b') = span isUpper input
    (b, c') = span isDigit b'
    (c, d) = span isUpper c'

main :: IO ()
main = do
  hSetBuffering stdin (BlockBuffering (Just 4096))
  n' <- readLn
  replicateM_ n' (putStrLn . solve =<< getLine)

module Main (main)
    where

import Data.List (foldl', unfoldr)
import Data.Tuple (swap)
import Data.Char (ord, chr, isAsciiUpper, isDigit)
import Control.Monad (replicateM)

toCartesian :: String -> String
toCartesian xs = 'R':row ++ 'C':show col
    where (q,row) = span isAsciiUpper xs
          col = foldl' (\r c -> 26 * r + ord c - ord 'A' + 1) 0 q

toExcel :: String -> String
toExcel (_:xs) = col ++ row
    where (row,_:ccol) = span isDigit xs
          col = reverse . map (\i -> chr $ ord 'A' + i) . go $ read ccol
          go 0 = []
          go n = let (q,r) = divMod n 26
                     (cur,next) = if r == 0 then (25,q - 1) else (r - 1,q)
                   in cur:go next

main :: IO ()
main = putStr . unlines . map solve =<< flip replicateM getLine =<< readLn
    where solve xs
            | all isDigit $ dropWhile isAsciiUpper xs = toCartesian xs
            | otherwise = toExcel xs

module Main where

import Text.ParserCombinators.ReadP
import Control.Monad
import Data.Char
import Data.List

main = do
    n <- read `liftM` getLine :: IO Int

    replicateM_ n $ getLine >>= putStrLn . translate

translate :: String -> String
translate s = fst $ head $ readP_to_S ( mplus
        ( do
            _ <- char 'R' :: ReadP Char
            row <- munch1 isDigit
            _ <- char 'C'
            col <- munch1 isDigit
            eof
            return $ digitToAlpha col ++ row
        ) ( do
            col <- munch1 isAlpha
            row <- munch1 isDigit
            eof
            return $ "R" ++ row ++ "C" ++ alphaToDigit col
        )
    ) s

digitToAlpha s =
    let n = read s
        digits26 = reverse $ digits26' (n-1)
        digits26' n =
            if n < 26
                then [n]
                else ( n `mod` 26 ) : digits26' ( n `div` 26 - 1 )
    in map ( chr . ( + ( ord 'A' ) ) ) digits26

alphaToDigit s =
    show $ foldl' (\acc d ->
            acc * 26 + 1 + ord d - ord 'A'
        ) 0 s

{-# LANGUAGE UndecidableInstances   #-}
{-# LANGUAGE ExtendedDefaultRules   #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE OverlappingInstances   #-}
-- ~ {-# LANGUAGE TypeSynonymInstances   #-}
-- ~ {-# LANGUAGE IncoherentInstances    #-}
import Data.Char
import Data.Typeable

-- ~ module MyModule where

------------------------------------------------------------------------
class (Show a) => MyToString a where
    mytoString :: a -> String

instance (Show a) => MyToString a where
    mytoString = show

instance {-# OVERLAPPING #-} MyToString String where
    mytoString = id

instance {-# OVERLAPPING #-} MyToString Char where
    mytoString c = [c]

------------------------------------------------------------------------
printList :: (MyToString a) => [a] -> IO()
printList [] = return()
printList (x : xs) =    do
                        putStrLn $ mytoString $ x
                        printList xs

main =  do
        content <- getContents
        printList $ map convert $ drop 1 $ lines $ content

isExcel :: String -> Bool
isExcel s = let func :: String -> Integer -> Bool
                func [] n
                    | n == 2 = True
                    | otherwise = False
                func (x : xs) 0
                    | isDigit x = False
                    | otherwise = func xs 1
                func (x : xs) 1
                    | isDigit x = func xs 2
                    | otherwise = func xs 1
                func (x : xs) 2
                    | isDigit x = func xs 2
                    | otherwise = False
            in func s 0

convert :: String -> String
convert s
    | isExcel s =   let x = splitExcel s
                    in "R" ++ (snd x) ++ "C" ++ (convFromExcel $ fst x)
    | otherwise =   let x = splitNotExcel s
                    in (convToExcel $ snd x) ++ (fst x)

splitNotExcel :: String -> (String, String)
splitNotExcel s =   let func :: (String, String) -> (String, String)
                        func (s1, x:xs)
                            | x == 'R' = func (s1, xs)
                            | x == 'C' = (s1, xs)
                            | otherwise = func (s1 ++ [x], xs)
                    in func ("", s)

convToExcel :: String -> String
convToExcel s = let func :: String -> Int -> String
                    func s 0 = s
                    func s n = func ([chr $ (mod (n-1) 26) + (ord 'A')] ++ s) $ div (n - (mod (n-1) 26)) 26
                in func [] (read s)

splitExcel :: String -> (String, String)
splitExcel s = break isDigit s

convFromExcel :: String -> String
convFromExcel s =   let func :: String -> Int -> String
                        func [] n = show n
                        func (x : xs) n = func xs $ n * 26 + (ord x) - (ord 'A') + 1
                    in func s 0

import Control.Monad
import Data.Char
import Text.Printf

toAlphabetic :: Int -> String
toAlphabetic 0 = ""
toAlphabetic n =
    let quotient = (n - 1) `div` 26
        remainder = (n - 1) `mod` 26
        current = chr $ (ord 'A') + remainder
        recur = toAlphabetic quotient
    in recur ++ [current]

toFirstForm :: String -> String -> String
toFirstForm r c' =
    let c = toAlphabetic $ read c'
    in c ++ r

toDigit :: String -> Int
toDigit = foldl (\accum current -> accum * 26 + (ord current - ord 'A' + 1)) 0

toSecondForm :: String -> String -> String
toSecondForm r c = "R" ++ c ++ "C" ++ (show $ toDigit r)

transform :: [String] -> String
transform [_, r, _, c] = toFirstForm r c
transform [r, c] = toSecondForm r c

splitByAlphaNumber :: [String] -> Char -> [String]
splitByAlphaNumber [] current = [[current]]
splitByAlphaNumber parsed current =
    let lastElement = last parsed
        lastLetter = last lastElement
    in if isDigit lastLetter == isDigit current
        then (init parsed) ++ [lastElement ++ [current]]
        else parsed ++ [[current]]

parseInput :: String -> [String]
parseInput = foldl splitByAlphaNumber []

solve :: String -> String
solve = transform . parseInput

readInput _ = do
    input <- getLine
    return input

main = do
    input <- getLine
    let n = read input :: Int
    inputs <- forM [1..n] readInput
    forM inputs $ (printf "%s\n") . solve

import Data.Char
import Data.List
import Data.Maybe

main = do
    n <- readLn
    lst <- sequence $ take n $ repeat getLine
    mapM_ (putStrLn . convert) lst

convert s | isRC s    = fromRC s
          | otherwise = toRC s

isRC ('R' : c1 : xs) | isDigit c1 && any (== 'C') xs = True
isRC _ = False

fromRC s = let
               cPos = fromJust $ findIndex (== 'C') s
               rowStr = drop 1 $ take cPos s
               col::Int
               col = read $ drop (cPos + 1) s
               unfun b | b == 0    = Nothing
                       | otherwise = Just (chr $  bb `mod` 26 + ord 'A', bb `div` 26)
                                     where bb = b - 1
               colStr = reverse $ unfoldr unfun $ col
           in
               colStr ++ rowStr

toRC s = let
             rowPos = fromJust $ findIndex isDigit s
             (colStr, rowStr) = splitAt rowPos s
             foldfun b a = b * 26 + ord a - ord 'A' + 1
             col = foldl foldfun 0 colStr
         in
             "R" ++ rowStr ++ "C" ++ show col

import Data.Char (isDigit, chr, ord)
import Control.Monad (replicateM_)
import Data.List (groupBy)

main :: IO ()
main = getLine >>= (\n -> replicateM_ (read n) (fmap (process.splitCode) getLine >>= putStrLn))

process [_,r,_,c] = (reverse.asBC) (read c) ++ r
process [b,n] = "R" ++ n ++ "C" ++ (show (bcToInt (reverse b)))
process _ = undefined
splitCode = groupBy (\c1 c2 -> isDigit c1 && isDigit c2 || not (isDigit c1) && not (isDigit c2))

bcToInt "" = 0
bcToInt (c:cs) = (ord c - ord 'A' + 1) + 26 * (bcToInt cs)

asBC :: Int -> String
asBC val  | val > 0 = ch : (asBC dv)
          | otherwise = ""
          where dv = (val - 1) `div` 26
                md = val `mod` 26
                ch = if md == 0 then 'Z'
                                else chr (ord 'A' + md - 1)

import Data.Char

main = do
	n<-getLine
	reading (read n)

reading 0  = do
	putStrLn []
reading a = do
	s<-getLine
	putStrLn $ pars s
	reading (a-1)

pars s
 | s=="" = ""
 | head s == 'R' && length s>=2 && isDigit (s!!1) && elem 'C' s = (numberToLetters (read (tail cPart)))
                                  ++ rPart
 | otherwise = "R"++sPart++ "C" ++  ( show (lettersToNumber fPart))
                where  rPart = (takeWhile isDigit (tail s))
                       cPart = dropWhile isDigit (tail s)
                       fPart = takeWhile (not.isDigit) s
                       sPart = dropWhile (not.isDigit) s

lettersToNumber::String->Integer
lettersToNumber []= 0
lettersToNumber s = toInteger (ord (head s)-ord 'A'+1) * 26^(length s-1)+ (lettersToNumber $ tail s)

numberToLetters::Integer->String
numberToLetters 0 = ""
numberToLetters n
  | mod n 26==0 = reverse$"Z" ++ reverse (numberToLetters  (div n 26-1))
  | otherwise   = reverse$ [chr (fromIntegral (mod n 26 + fromIntegral( ord 'A')-1))]
                  ++ reverse (numberToLetters $ div n 26)

module Main
where

import System.IO
import Data.Char
import Data.List

data Cell = RCCell Integer Integer | CharCell String Integer deriving (Eq, Show)

readFormat s = if srest2 == "" then CharCell s1 (read s2) else RCCell (read s2) (read s4)
    where (s1, srest1) = span isAlpha s
          (s2, srest2) = span isDigit srest1
          (_, s4) = span isAlpha srest2

charDig c = toInteger(ord c - ord 'A')

charToNumber' (x:xs) = charToNumber' xs * 26 + charDig x + 1
charToNumber' _ = 0

charToNumber s = charToNumber' $ reverse s

digChar n = chr (fromInteger n + ord 'A')

numberToChar' n = (digChar (m `mod` 26)):(if m > 25 then numberToChar' (m `div` 26) else "")
  where m = n - 1

numberToChar n = reverse $ numberToChar' n

transformFormat (RCCell x y) = (CharCell (numberToChar y) x)
transformFormat (CharCell x y) = (RCCell y (charToNumber x))

showFormat (RCCell x y) = "R" ++ show x ++ "C" ++ show y
showFormat (CharCell x y) = x ++ show y

transform arg = showFormat $ transformFormat $ readFormat arg

main = do
       l <- hGetContents stdin
       let args = lines l
       let cases = (read $ args !! 0)::Int
       hPutStrLn stdout $ unlines $ map transform $ take cases $ tail args
       return ()

import Data.Char

main :: IO()
main = getContents >>= mapM_ (putStrLn . solve) . tail . lines

is_digit :: Char -> Bool
is_digit c = (ord '0') <= (ord c) && (ord c) <= (ord '9')

is_rxcy :: String -> Bool
is_rxcy (x:y:xs) | (is_digit x) && (not (is_digit y)) = True
                 | otherwise = is_rxcy (y:xs)
is_rxcy s = False

solve :: String -> String
solve s | is_rxcy(s) = conv1 s
        | otherwise = conv2 s

get_first_digit :: String -> String
get_first_digit (x:xs) | is_digit x = (x:xs)
                       | otherwise = get_first_digit xs

get_first_non_digit :: String -> String
get_first_non_digit (x:xs) | is_digit x = get_first_non_digit xs
                           | otherwise = xs

read_num :: String -> Int
read_num s = read_num' s 0
    where
        read_num' :: String -> Int -> Int
        read_num' "" num = num
        read_num' (x:xs) num | is_digit x = read_num' xs (num * 10 + (ord x) - (ord '0'))
                             | otherwise = num

conv1 :: String -> String
conv1 (x:xs) =
    let row = read_num(xs)
        col = read_num(get_first_non_digit(xs))
    in  (num2alpha col) ++ (show row)

num2alpha :: Int -> String
num2alpha 0 = ""
num2alpha num = (num2alpha (div (num - 1) 26)) ++ [(chr ((rem (num - 1) 26) + ord('A')))]

conv2 :: String -> String
conv2 s =
    let col = read_alpha(s)
        row = read_num(get_first_digit(s))
    in "R" ++ (show row) ++ "C" ++ (show col)

read_alpha :: String -> Int
read_alpha s = read_alpha' s 0
    where
        read_alpha' "" num = num
        read_alpha' (x:xs) num | is_digit x = num
                               | otherwise = read_alpha' xs (num * 26 + (ord(x) - ord('A') + 1))

-- file cf_p1B.hs
import Data.Char
import Data.List

myTansform :: String -> String
myTansform xs =
    case segments of
      ("R" : row : "C" : col : []) -> num2char (read col) ++ row
      (col : row : []) -> "R" ++ row ++ "C" ++ show (char2num col)
    where segments = groupBy (\l r -> isDigit l == isDigit r) xs
          num2char = map (\x -> chr (ord 'A' + (x - 1) `mod` 26)) . reverse . takeWhile (>0) . iterate (\x -> (x-1) `div` 26)
          char2num = foldl' (\acc x -> acc * 26 + x) 0 . map (\x -> ord x - ord 'A' + 1)

main = interact $ intercalate "\n" . map myTansform . tail . lines

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

import Data.Char

data CoordinateType = A | B deriving (Eq, Show)

main = do
	contents <- getLine
	let
		n = read $ head $ lines contents
	coordinates <- getLines n
	mapM_ putStrLn $ convertCoordinates coordinates
	return ()

getLines :: Int -> IO [String]
getLines 0 = return []
getLines n = do
	x <- getLine
	xs <- getLines (n-1)
	return (x:xs)

-- Type A if not letters are found after a number (ABXY)
-- Type B if letters are found after a number (RXCY)
-- Regular expressions could be used, but let's keep things simple
coordinateType :: String -> CoordinateType
coordinateType (x:xs) = coordinateType' x xs
	where
		coordinateType' :: Char -> String -> CoordinateType
		coordinateType' _ [] = A
		coordinateType' prev (x:xs)
			| isDigit prev && isLetter x = B
			| otherwise = coordinateType' x xs

letterToNum :: Char -> Int
letterToNum letter = ord letter - 65

numToLetter :: Int -> Char
numToLetter num = chr $ num + 65

letterColToNum :: String -> Int
letterColToNum [] = 0
letterColToNum (x:xs) = 26^length(xs)*((letterToNum x) + 1) + letterColToNum xs

numToLetterCol :: Int -> String
numToLetterCol num = reverse $ numToLetterCol' num
	where
		numToLetterCol' :: Int -> String
		numToLetterCol' num
			| num < 26 = [numToLetter num]
			| otherwise = numToLetter (num `mod` 26) : numToLetterCol' (num `quot` 26 - 1)

translateCoordinate :: String -> String
translateCoordinate coord
	| coord_type == A =
		let
			col = takeWhile (isLetter) coord
			row = takeWhile (isDigit) $ dropWhile (isLetter) coord
		in
			"R" ++ row ++ "C" ++ (show $ letterColToNum col)
	| coord_type == B =
		let
			col = read $ tail $ dropWhile (isDigit) $ tail coord
			row = takeWhile (isDigit) $ tail coord
		in
			numToLetterCol (col-1) ++ row
	where
		coord_type = coordinateType coord

convertCoordinates :: [String] -> [String]
convertCoordinates [] = []
convertCoordinates (x:xs) = translateCoordinate x : convertCoordinates xs

{-
    Convert between two ways to write a row/column
    1) R##C##
    2) LL##
    in 1) the row and column is simply numbered
    in 2) it is encoded, column as a number in pseudo base-26 using letters
    row simply written afterward
-}

import Data.List
import Data.Char

s2i :: String -> Int
s2i = foldl (\s d -> 26*s + ord d - ord 'A' + 1) 0

i2s :: Int -> String
i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv :: String -> String
conv s =
        case groupBy (\a b -> isDigit a == isDigit b) s of
            -- R##C## case
            [_, r, _, c] -> (reverse . i2s . read $ c) ++ r
            [c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = interact $ unlines . map conv . tail . lines

import Control.Monad
import Data.Char
import Data.List
import System.IO

s2i = foldl (\a x -> 26*a + ord x - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = interact $ unlines . map conv . tail . lines

import Data.Char
import Data.List
intToStr 0 = []
intToStr x = (intToStr $ (x - 1) `div` 26) ++ [chr $ (x - 1) `mod` 26 + ord 'A']
strToInt = foldl (\ s c -> 26 * s + ord c - ord 'A' + 1) 0
f str = case parse str of
            [_,r,_,c] -> (intToStr . read $ c) ++ r
            [c,r] -> "R" ++ r ++ "C" ++ (show . strToInt $ c)
        where
            parse = groupBy (\a b -> isDigit a == isDigit b)
main = interact $ unlines . map f . tail . lines

import Data.Char
import Debug.Trace
import Control.Monad

data IdType = Excel | RC

getInput :: IO [String]
getInput = do
	linesnum <- (liftM read) getLine
	sequence $ replicate linesnum getLine

identifyType :: String -> IdType
identifyType s = if head s /= 'R'
	then Excel
	else if not . isDigit $ s !! 1
		then Excel
		else if any (not . isDigit) $ drop 2 s then RC else Excel

excelToRC :: String -> String
excelToRC s = "R" ++ row ++ "C" ++ convertedColumn
	where
		(column, row) = parseExcel s
		convertedColumn = (show . id) $ foldl decodeAlpha 0 column
		parseExcel = break isDigit
		decodeAlpha t c = (t * 26) + (ord c - ord 'A' + 1)

rCToExcel :: String -> String
rCToExcel s = convertedColumn ++ row
	where
		(row, column) = parseRc s
		parseRc s = let (a,b) = break (== 'C') (tail s) in (a, tail b)
		convertedColumn = decodeNumber (read column) ""
		decodeNumber 0 s = s
		decodeNumber x s = if x < 26
			then decodeDigit x : s
			else decodeNumber d newS
				where
					(d, m) = divMod' x 26
					newS = decodeDigit m : s
		divMod' a b = if m == 0 then (d - 1, b) else (d, m)
			where
				(d, m) = divMod a b

		decodeDigit x = chr (ord 'A' + x - 1)

convert :: String -> String
convert s = case identifyType s of
	Excel -> excelToRC s
	RC -> rCToExcel s

main = do
	coords <- getInput
	mapM_ (putStrLn . convert) coords

{-# LANGUAGE ScopedTypeVariables #-}
module Main where

import Data.List
import Data.Char

letters = map (\x -> chr (ord 'A' + (x - 1) `mod` 26)) . reverse . takeWhile (>0) . iterate (\x -> (x-1) `div` 26)
numbers = sum . zipWith (*) (iterate (*26) 1) . reverse . map (\x -> ord x - ord 'A' + 1)

convert :: [String] -> String
convert ("R":r:"C":c:[]) = letters (read c) ++ r
convert (c:r:[]) = "R" ++ r ++ "C" ++ show (numbers c)

main = do
    (n :: Int,cells) <- getContents >>= return . (\(n:cells) -> (read n,map (map toUpper) cells)) . lines
    mapM (putStrLn . convert . groupBy (\l r -> isDigit l == isDigit r)) (take n cells)

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Function
import Data.Ord
import Data.Bits
import Data.Monoid
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main= someFunc
rIn x= fst $ fromJust  $ C.readInt x
someFunc::IO()
someFunc = readLn >>= \n-> (solve=<<forM [1..n] (\i->C.getLine) )
solve xs = forM_ xs $ \i->  C.putStrLn $ slv1 i
slv1 xs = slv2 $ second  (C.break (isLetter)) $ C.break (isDigit) xs
slv2 (a,(b,c))= if c/=C.empty then C.append (slv5 $ rIn $ C.tail c) b else  C.append (C.cons 'R' (C.init b)) (C.cons 'C' $ slv3 a)
se_t2 = Set.fromList (['A'..'Z'])
slv3::C.ByteString->C.ByteString
slv3 xs =C.pack $ show $ fst $ C.foldr (\a (b1,b2)->((Set.findIndex a se_t2+1)* 26^b2 +b1, b2+1)) (0,0) xs
slv4 0 = []
slv4 x=let md = x `mod` 26; dv= x `div` 26 in slv4 (if md==0 then dv-1 else dv) ++[if md==0 then 26 else md]
slv5 x =C.pack $ map (flip Set.elemAt se_t2.(+(-1))) $ slv4 x

{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.List

i2s a = reverse $ go a
  where
    go :: Int -> String
    go 0 = ""
    go !a = chr (ord 'A' + (a - 1) `mod` 26) : go ((a - 1) `div` 26)

s2i :: String -> Int
s2i = foldl' (\a x -> 26 * a + ord x - ord 'A' + 1) 0

ans s = case groupBy (\a b -> isDigit a == isDigit b) s of
          [_, r, _, c] -> (i2s . read $ c) ++ r
          [c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)
main = interact $ unlines . map ans . tail . lines

{-# LANGUAGE ViewPatterns #-}
import Data.Char
import Data.List

a2n = foldl' (\i s -> ord s - ord 'A' + 1 + i*26) 0
n2a 0 = []
n2a n = chr (ord 'A' + (n - 1) `mod` 26) : n2a ((n - 1) `div` 26)

match = groupBy (\a b -> isDigit a == isDigit b)
solve (match -> [col, row]) = "R" ++ row ++ "C" ++ (show . a2n $ col)
solve (match -> [_, row, _, col]) = (reverse . n2a . read $ col) ++ row

main = interact $ unlines . map solve . tail . lines

import Data.Char
import Text.ParserCombinators.ReadP

fromChar :: Char -> Int
fromChar c = (ord c - ord 'A' + 1)

toChar :: Int -> Char
toChar n
  | n < 0 || n > 26  =  error "toChar: argument not in [1..26]"
  | otherwise        =  chr (ord 'A' + n - 1)

fromABC :: String -> Int
fromABC "" = 0
fromABC s = sum (zipWith (*) (map fromChar s) (_26 (length s)))
  where
    _26 0 = []
    _26 n = (26^(n-1)):(_26 (n-1))

toABC :: Int -> String
toABC 0  =  ""
toABC n
  | n <= 26    =  [toChar n]
  | a == 0     =  (toABC (div n 26 - 1)) ++ "Z"
  | otherwise  =  (toABC (div n 26)) ++ [toChar a]
  where
    a = mod n 26

parserRC :: ReadP (Int, Int)
parserRC = do
    string "R"
    row <- many1 $ satisfy isDigit
    string "C"
    col <- many1 $ satisfy isDigit
    return (read col, read row)

parserA1 :: ReadP (Int, Int)
parserA1 = do
    col <- many1 $ satisfy isAlpha
    row <- many1 $ satisfy isDigit
    return (fromABC col, read row)

getCell :: ReadP (Int, Int) -> String -> Maybe (Int, Int)
getCell parser s
  | 0 < length xs  =  Just (fst (head xs))
  | otherwise  =  Nothing
  where
    xs  =  filter (\x -> snd x == "") (readP_to_S parser s)

checkString :: ReadP (Int, Int) -> String -> Bool
checkString parser s  =  getCell parser s /= Nothing

checkRC :: String -> Bool
checkRC  =  checkString parserRC

checkA1 :: String -> Bool
checkA1  =  checkString parserA1

toRC :: (Int, Int) -> String
toRC (n, m)  =  concat ["R", show m, "C", show n]

toA1 :: (Int, Int) -> String
toA1 (n, m)  =  concat [toABC n, show m]

solve :: String -> String
solve s
  | checkRC s  =  toA1 (r, c)
  | checkA1 s  =  toRC (n, m)
  | otherwise  =  "NO"
  where
    (Just (r, c))  =  getCell parserRC s
    (Just (n, m))  =  getCell parserA1 s

main :: IO ()
main = do
    n <- readLn
    lines <- sequence (replicate n getLine)
    sequence_ (map (putStrLn . solve) lines)

-- Codeforces 1B

import Data.List
import Data.Char

main :: IO ()
main = interact $ unlines . map solve . tail . lines

-- use groupBy to detect the kind of input.

solve :: String -> String
solve s = case groupBy (\a b -> isDigit a == isDigit b) s
    of {
        [_, r, _, c]    -> (reverse $ i2s $ read c) ++ r;
        [c, r]          -> "R" ++ r ++ "C" ++ (show $ s2i c)
    }

s2i :: String -> Int
s2i = foldl' (\s d -> 26 * s + ord d - ord 'A' + 1) 0

i2s :: Int -> String
i2s 0 = []
i2s a = chr (ord 'A' + (a-1) `mod` 26) : (i2s $ (a-1) `div` 26)

import Control.Monad

readAlphas (x : xs) | 'A' <= x && x <= 'Z' =
  x : readAlphas xs
readAlphas _ = ""

readDigits (x : xs) | '0' <= x && x <= '9' =
  x : readDigits xs
readDigits _ = ""

crToXY c r = 'R' : show r ++ 'C' : (show . convert . reverse) c
  where
    convert [] = 0
    convert (x : xs) = let v = fromEnum x - 64 in
      v + convert xs * 26

xyToCR x y = convert y ++ show x
  where
    convert 0 = ""
    convert n = convert (div' n 26) ++ [toEnum (mod' n 26 + 64)]
      where
        mod' a b = let r = mod n 26 in
          if r == 0 then 26 else r
        div' a b = div (a - mod' a b) b

main = do
  line <- getLine
  let n = read line :: Int
  forM_ [1..n] $ \i -> do
    line <- getLine
    let a = readAlphas line
    let line' = drop (length a) line
    let b = readDigits line'
    let line'' = drop (length b) line'
    case line'' of
      "" -> do let c = a
               let r = read b :: Int
               putStrLn $ crToXY c r
      _  -> do let x = read b :: Int
               let y = read (drop 1 line'') :: Int
               putStrLn $ xyToCR x y

import           Data.Char
import           Data.List

--rc2l :: (Foldable t) => t Char -> Int
rc2l x = foldl (\a b -> 26*a + ord b - ord 'A' + 1) 0 x

l2rc :: Int -> [Char]
l2rc 0 = []
l2rc x = chr (ord 'A' + (x-1) `mod` 26) : (l2rc $ (x-1) `div` 26)

solution :: [Char] -> [Char]
solution xs = case groupBy(\a b -> isDigit a == isDigit b) xs of
                [_, r, _, c] -> (reverse . l2rc . read $ c) ++ r
                [c, r] -> "R" ++ r ++ "C" ++ (show . rc2l $ c)

main = interact $ unlines . map solution . tail . lines

import Data.Char
import Data.List

intToStr 0 = []
intToStr x = (intToStr $ (x - 1) `div` 26) ++ [chr $ (x - 1) `mod` 26 + ord 'A']

strToInt = foldl (\n c -> 26 * n + ord c - ord 'A' + 1) 0

solver str = case parse str of
               [_,r,_,c] -> (intToStr . read $ c) ++ r
               [c, r] -> "R" ++ r ++ "C" ++ (show . strToInt $ c)
             where
               parse = groupBy (\a b -> isDigit a == isDigit b)

main = interact $ unlines . map solver . tail . lines

import Data.List
import Data.Char

fromNumber :: Int -> String
fromNumber 0 = []
fromNumber x = (fromNumber y) ++ [chr (z + (ord 'A') - 1)]
    where z' = x `mod` 26
          z = if z' == 0 then 26 else z'
          y' = x `div` 26
          y = if z' == 0 then y' - 1 else y'

toNumber :: String -> Int
toNumber s = foldl (\sum c -> sum * 26 + (ord c - ord 'A' + 1)) 0 s

solve input =
    case pattern of
        ["R", r, "C", c] -> (fromNumber (read c)) ++ r
        [c, r]           -> "R" ++ r ++ "C" ++ (show (toNumber c))
    where pattern = groupBy (\x y -> isDigit x == isDigit y) input

main = interact $ unlines . map solve . tail . lines

import Data.Char
import Data.List

calcAlpha :: String -> Int -> Int
calcAlpha (x:[]) num = num * ((ord x) - (ord 'A') + 1)
calcAlpha (x:xs) num = num * ((ord x) - (ord 'A') + 1) + (calcAlpha xs (num*26))

alphaToRC alpha num = "R" ++ num ++ "C" ++ show (calcAlpha (reverse alpha) 1)

-- 26 / 26 = 1 % 0
-- 0  / 26 = 0 % 1

calcRC n
 |n `div` 26 == 0 = [chr (ord 'A' + (n `mod` 27) )]
 |otherwise = calcRC (-1+(n `div` 26)) ++ [chr (ord 'A' + (n `mod` 26))]

rcToAlpha :: String -> String -> String
rcToAlpha r c = calcRC ((read c :: Int)-1) ++ r

parseInp :: String -> String -> [String]
parseInp [] y = [y]
parseInp (x:xs) y
 |y  == []   = parseInp xs [x]
 |isDigit (x) == isDigit (head y) = parseInp xs (y++[x])
 |otherwise =  [y] ++ parseInp xs [x]

solveTC :: Integer -> IO ()
solveTC n = do
             if (n == 0)
              then return ()
              else do
                     line <- getLine
                     let inp = parseInp line ""
                     if length inp == 2
                        then putStrLn $ alphaToRC (inp !! 0) (inp !! 1)
                        else putStrLn $ rcToAlpha (inp !! 1) (inp !! 3)

                     solveTC (n-1)

main = do
        line <- getLine
        let tc = (read line :: Integer)
        solveTC tc

import Data.Char (ord, chr)

main :: IO ()
main = do
  s <- getContents
  putStr (unlines $ map process (tail $ lines s))

charId :: Char -> Int
charId c = ord c - ord 'A'

charFromId :: Int -> Char
charFromId c = chr ((ord 'A') + c)

charBase = (charId 'Z') + 1

process :: String -> String
process s | (length parsed) == 2 = coordsToRC $ coordsFromAB parsed
          | otherwise            = coordsToAB $ coordsFromRC parsed
    where parsed = chainParse [isLetter, isDigit, isLetter, isDigit] s

coordsFromAB :: [String] -> (Int, Int)
coordsFromAB [col, row] = (read row, lettersToInt col)

coordsFromRC :: [String] -> (Int, Int)
coordsFromRC ["R", row, "C", col] = (read row, read col)

lettersToInt :: String -> Int
lettersToInt s = sum $ map (\(val, k) -> val*k) (zip (reverse $ map (\c -> charId c + 1) s) factors)
    where factors = iterate (*charBase) 1

intToLetters :: Int -> String
intToLetters rawn = reverse $ map one (zip (1:pows) (takeWhile (<=n) shifts))
    where
        n = rawn - 1

        one :: (Int, Int) -> Char
        one (p, s) = charFromId (((n - s) `div` p) `mod` charBase)

        pows = (iterate (*charBase) charBase)

        shifts :: [Int]
        shifts = gen pows 0
            where gen (x:xs) l = l:(gen xs (l+x) )

coordsToRC :: (Int, Int) -> String
coordsToRC (row, col) = "R" ++ (show row) ++ "C" ++ (show col)

coordsToAB :: (Int, Int) -> String
coordsToAB (row, col) = intToLetters col ++ show row

chainParse :: [( Char -> Bool )] -> String -> [String]
chainParse [] _ = []
chainParse _ "" = []
chainParse (f:fs) s = (extractChars f s):(chainParse fs (eatChars f s))

eatChars :: ( Char -> Bool ) -> String -> String
eatChars _ [] = []
eatChars f (c:cs) | f c       = eatChars f cs
                  | otherwise = (c:cs)

extractChars :: ( Char -> Bool ) -> String -> String
extractChars _ [] = []
extractChars f (c:cs) | f c       = c:(extractChars f cs)
                      | otherwise = ""

isDigit :: Char -> Bool
isDigit c = c>='0' && c<='9'

isLetter :: Char -> Bool
isLetter c = (c>='a' && c<='z') || (c>='A' && c<='Z')

import Control.Monad
import Data.Char
import Data.List
import Control.Applicative

main = do
  n <- readLn
  replicateM_ n (getLine >>= putStrLn . solve)

solve :: String -> String
solve str =
  let (a,(b,c)) = span isDigit <$> span isUpper str
  in if null c
       then encode1 (read b) (decodeCol a)
       else encode2 (read b) (read (snd (span isUpper c)))

encode1 :: Int -> Int -> String
encode1 row col = "R" ++ show row ++ "C" ++ show col

encode2 :: Int -> Int -> String
encode2 row col = encodeCol col ++ show row

decodeCol :: String -> Int
decodeCol = foldl (\a c -> 26*a + ord c - ord 'A' + 1) 0

encodeCol :: Int -> String
encodeCol r = reverse . unfoldr (\i -> if i == 0 then Nothing else Just (chr ((i-1) `mod` 26 + ord 'A'), (i-1) `div` 26)) $ r

import Control.Applicative
import Data.List
import Data.Array.Unboxed
import Data.Char

table = listArray (0, 25) ['A' .. 'Z'] :: UArray Int Char

parse xs
  | null cs   = Left (bs, as)
  | otherwise = let Left (as', bs') = parse cs in Right (bs, as') where
  (as, (bs, cs)) = span isDigit <$> span isUpper xs

numToStr n = reverse $ f n where
  f x = case (x - 1) `quotRem` 26 of
    (0 , i) -> [table ! i]
    (n', i) -> table ! i : f n'

strToNum xs = f $ reverse xs where
  f []       = 0
  f (c : cs) = (fromEnum c - fromEnum 'A' + 1) + 26 * f cs

conv xs = case parse xs of
  Left  (rs, cs) -> "R" ++ rs ++ "C" ++ show (strToNum cs)
  Right (rs, cs) -> numToStr (read cs) ++ rs

solve (n : xs) = conv <$> take (read n) xs

main = interact $ unlines . solve . lines

import Control.Monad
import Data.Char
import Data.Sequence (Seq, empty, (|>))
import Data.Foldable (toList)

parseRowColFormat :: String -> Maybe (Int, Int)
parseRowColFormat s@(x : _) = if x == 'R' then go "" "" s else Nothing where
    go "" "" [] = Nothing
    go (r:rs) "" [] = Nothing
    go rows@(r:rs) "" (_: xs) = go rows xs []
    go rows@(r:rs) cols@(c:cs) [] = Just (read rows, read cols)
    go "" "" (_ : xs) = go (takeWhile isDigit xs) "" (dropWhile isDigit xs)

parseStandartFormat :: String -> Maybe (String, Int)
parseStandartFormat s = go "" "" s where
    go "" "" [] = Nothing
    go (c:cs) "" [] = Nothing
    go cols@(c:cs) "" xss@(x:xs) = if any isAlpha xss then Nothing else go cols xss []
    go cols@(c:cs) rows@(r:rs) [] = Just (cols, read rows)
    go "" "" xs = go (takeWhile isAlpha xs) "" (dropWhile isAlpha xs)

col2Alpha :: Int -> String
col2Alpha = toList . go where
    go 0 = empty
    go col = go ((col - 1) `div` 26) |> chr((col - 1) `mod` 26 + ord('A'))

alpha2Col :: String -> Int
alpha2Col col = foldl (\acc c -> acc*26 + ord(c) - ord('A') + 1) 0 col

parse :: String -> String
parse format = case parseRowColFormat format of
    Just (row, col) -> col2Alpha col ++ show row
    Nothing -> case parseStandartFormat format of
        Just (scol, srow) -> ('R' : show srow) ++ ('C' : (show $ alpha2Col scol))
        Nothing -> ""

main =
    read <$> getLine >>= \n ->
    replicateM_ n (parse <$> getLine >>= putStrLn)

module Main(main) where

import Control.Arrow
import Data.Char
import Data.List
import Numeric
import Data.Function

isRXCY = dropWhile isAsciiUpper >>> dropWhile isDigit >>> null >>> not
toRXCY = readInt 26 isAsciiUpper (\x -> ord x - ord 'A' +1) >>> head >>> \ (c,r) -> 'R': r ++ "C" ++ show c

fromRXCY' = read >>> unfoldr (\x -> if x==0 then Nothing else Just ((x-1)`mod`26 + 1,(x-1)`div`26)) >>> reverse >>> map (\x -> chr $ x-1 + ord 'A')
fromRXCY = groupBy ((==) `on` generalCategory) >>> \ (_:r:_:c:_) -> fromRXCY' c ++ r

main = do
  n:xs <- lines `fmap` getContents
  putStr $ ($ xs) $ take (read n) >>> map (\x -> if isRXCY x then fromRXCY x else toRXCY x) >>> unlines

import Data.Char
import Data.List

main :: IO ()
main = interact $ concatMap ((++"\n") . show . convert . read) . tail . lines

data Cell = Ax String Integer | Rxcy Integer Integer

instance Show Cell where
  show (Ax a x) = a ++ show x
  show (Rxcy x y) = "R" ++ show x ++ "C" ++ show y

instance Read Cell where
  readsPrec _ s = [(listToCell list, "")]
    where list = foldl go [] s
          go [] c = [[c]]
          go xs c | isAlpha (head (head xs)) == isAlpha c = (head xs++[c]):tail xs
                  | otherwise = [c]:xs
          listToCell [y, "C", x, "R"] = Rxcy (read x) (read y)
          listToCell [x, a] = Ax a (read x)
          listToCell _ = error "Input error"

convert :: Cell -> Cell
convert (Ax a x) = Rxcy x idx
  where nums = map (\c -> fromIntegral $ ord c - ord 'A' + 1) (reverse a)
        idx = sum $ map (\(b, y) -> b * 26 ^ (y :: Integer)) $ zip nums [0..]
convert (Rxcy x y) = Ax str x
  where str = reverse $ unfoldr go y
        go 0 = Nothing
        go n = Just (chr (ord 'A' + fromIntegral m), d)
          where (d, m) = divMod (n - 1) 26

import Data.Char
import Data.List

main :: IO ()
main = interact $ foldr ((++) . (++"\n")) "" . map (show . convert . read) . tail . lines

data Cell = Ax String Integer
          | Rxcy Integer Integer

instance Show Cell where
  show (Ax a x) = a ++ show x
  show (Rxcy x y) = "R" ++ show x ++ "C" ++ show y

instance Read Cell where
  readsPrec _ s = [(cvt xxs, "")]
    where xxs = foldl (\xs c -> if null xs then [[c]] else (if isAlpha (head (head xs)) == isAlpha c then (head xs++[c]):(tail xs) else [c]:xs)) [] s
          cvt [y, "C", x, "R"] = Rxcy (read x) (read y)
          cvt [x, a] = Ax a (read x)
          cvt _ = error "Input error"

convert :: Cell -> Cell
convert (Ax a x) = Rxcy x idx
  where nums = map (\c -> fromIntegral $ ord c - ord 'A' + 1) (reverse a)
        idx = sum $ map (\(b, y) -> b * 26 ^ y) $ zip nums [0..]
convert (Rxcy x y) = Ax str x
  where str = reverse $ unfoldr (\n -> if n == 0 then Nothing else let (d, m) = divMod (n - 1) 26 in Just (['A'..'Z'] !! (fromIntegral m), d)) y

import Data.Char
import Data.Functor
import Data.List

convert :: String -> String
convert s = case groupBy (\a b -> isDigit a == isDigit b) s of
                 [_, r, _, c] -> rc2cr r c
                 [c, r]       -> cr2rc c r
  where rc2cr r c = (chr . (ord 'A' +) <$> reverse (basify (read c) 26)) ++ r
        cr2rc c r = concat ["R", r, "C", show (unbasify (flip (-) (ord 'A') . ord <$> reverse c) 26)]
        basify :: Int -> Int -> [Int]
        basify 0 _ = []
        basify n q = (n - 1) `mod` q : basify ((n - 1) `div` q) q
        unbasify :: [Int] -> Int -> Int
        unbasify [] _     = 0
        unbasify (a:as) q = unbasify as q * q + a + 1

main :: IO ()
main = do
  n <- read <$> getLine
  inp <- loop n
  mapM_ putStrLn $ convert <$> inp
  where loop :: Integer -> IO [String]
        loop 0 = return []
        loop n = do
          input <- getLine
          rest  <- loop $ n - 1
          return $ input : rest

module Main where

import Data.Char

readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
    [(x, "")] -> Just x
    _         -> Nothing

toString :: Int -> String
toString n = toStringAux n [] where
	toStringAux n ss = let (d, m) = divMod (n - 1) 26 in
		case d of
		0 -> chr (ord 'A' + m) : ss
		_ -> toStringAux d (chr (ord 'A' + m) : ss)

toInt :: String -> Int
toInt ss = toIntAux ss 0 where
	toIntAux (s : []) n = (ord s - ord 'A' + 1) + n * 26
	toIntAux (s : ss) n = toIntAux ss ((ord s - ord 'A' + 1) + n * 26)

readRC :: String -> Maybe (Int, Int)
readRC s =
	let (r, s') = break isDigit s;
		(rs, s'') = break isAlpha s';
		(c, cs) = break isDigit s'' in do
	rn <- readMaybe rs
	cn <- readMaybe cs
	return (rn, cn)

readCR :: String -> Maybe (String, Int)
readCR s =
	let (cs, rs) = break isDigit s in
	do
	rn <- readMaybe rs
	return (cs, rn)

process :: String -> String
process s = case readRC s of
	Just (r, c) -> toString c ++ show r
	_ -> case readCR s of
		Just (c', r') -> "R" ++ show r' ++ "C" ++ show (toInt c')
		_ -> ""

main :: IO ()
main = do
	input <- getContents
	putStrLn (unlines (map process (tail (lines input))))

module Main(main) where

import Data.List(tails,foldl')
import Data.Maybe(fromJust)
import Control.Applicative

readInt :: String -> Int
readInt = read

alphaToInt :: Char -> Int
alphaToInt c = fromJust . lookup c $ zip ['A'..] [1..26]

strToInt :: String -> Int
strToInt s = let l = length s in strToInt' s l 0
  where strToInt' [] _ r   = r
        strToInt' _ 0 r = r
        strToInt' (s:ss) l r = strToInt' ss (l-1) (r+(alphaToInt s)*26^(l-1))

intToAlpha :: Int -> Char
intToAlpha i = fromJust . lookup i $ zip [1..26] ['A'..]

intToStr :: Int -> String
intToStr = reverse . intToStr'
  where intToStr' 0 = ""
        intToStr' i = (intToAlpha ((i-1) `mod` 26 + 1)) : intToStr' ((i-1)`div`26)

isCharNum :: Char -> Bool
isCharNum c = any (c==) "0123456789"

isExcel :: String -> Bool
isExcel = not . any isChange . tails
  where isChange (x:y:_) = (isCharNum x) && (not $ isCharNum y)
        isChange [x] = False
        isChange [] = False

fromExcel :: String -> (Int,Int)
fromExcel = f . break isCharNum
  where f (c,r) = (strToInt c, readInt r)

toExcel :: (Int,Int) -> String
toExcel (c,r) = (intToStr c) ++ (show r)

fromOther :: String -> (Int,Int)
fromOther s = let ((_:r),(_:c)) = break (=='C') s in (readInt c, readInt r)

toOther :: (Int,Int) -> String
toOther (c,r) = "R" ++ show r ++ "C" ++ show c

calc :: String -> String
calc str =if isExcel str
            then toOther $ fromExcel str
            else toExcel $ fromOther str

main = do
  n <- readInt <$> getLine
  sequence_ $ take n $ repeat ((putStrLn . calc) =<< getLine)

import Data.Char
import Data.List

main = interact $ unlines . map convert . tail . lines
convert s = case parseAlternate s of
              Just a -> showTrad a
              Nothing -> showAlternate (parseTrad s)

parseAlternate :: String -> Maybe (Int,Int)
parseAlternate ('R' : s) = case reads s of
                             [(r, 'C' : cs)] -> Just (r,read cs)
                             _ -> Nothing
parseAlternate _ = Nothing
showAlternate (r,c) = 'R' : show r ++ 'C' : show c

parseTrad :: String -> (Int,Int)
parseTrad s = (read r,decode c)
    where (c,r) = break isDigit s
showTrad (r,c) = encode c ++ show r

encode = reverse . unfoldr f . pred
    where f n | n < 0     = Nothing
              | otherwise = Just (chr (ord 'A' + r), q-1) where (q,r) = n `divMod` 26
decode = foldl1' f . map ((subtract $ ord 'A' - 1) . ord)
    where f a b = 26*a + b

import Data.Char
main = do
  n <- getLine
  inpStrs <- getInput (read n)
  putStrLn(solve inpStrs)

getInput :: Integer -> IO [String]
getInput 0 = return []
getInput n = do
  inpStr <- getLine
  xs <- getInput (n-1)
  return (inpStr:xs)

solve :: [String] -> String
solve [] = ""
solve (x:xs) = change(x) ++ "\n" ++ solve(xs)

change :: String -> String
change x = if isRXCY px then toExcel xy else toRXCY xy
           where px = parse x ("","","","")
                 xy = mkXY px

isRXCY :: (String,String,String,String) -> Bool
isRXCY (a,b,c,d) = (c/="")

parse :: String -> (String,String,String,String) -> (String,String,String,String)
parse [] (a,b,c,d) = (a,b,c,d)
parse (x:xs) (a,b,c,d) = if isAlpha x then
                           if b == "" then parse xs (a++[x],b,c,d) else parse xs (a,b,c++[x],d)
                       else
                           if c == "" then parse xs (a,b++[x],c,d) else parse xs (a,b,c,d++[x])

mkXY :: (String,String,String,String) -> (Int,Int)
mkXY (a,b,c,d) = if isRXCY (a,b,c,d) then ((read b),(read d))
                 else ((read b),(stoi a))

stoi :: String -> Int
stoi [] = 0
stoi xs = baseChange 26 (map ctoi xs)
    where ctoi x = (ord x) - (ord 'A') + 1
          baseChange x = foldl (shiftAdd x) 0
              where shiftAdd x a b = a*x + b

toRXCY :: (Int,Int) -> String
toRXCY (x,y) = "R"++(show x)++"C"++(show y)
toExcel :: (Int,Int) -> String
toExcel (x,y) = (itos y) ++ (show x)
    where itos x | x==0 = ""
                 | x`mod`26 == 0 = (itos (x`div`26 - 1)) ++ "Z"
                 | otherwise = (itos (x`div`26)) ++ (itoc (x`mod`26))
              where itoc x = [chr((ord 'A') + x - 1)]

import Data.Char
import Control.Monad

readRXCY :: String -> Maybe (Int, Int)
readRXCY ('R':s) = case span isNumber s of
    (x@(_:_), 'C':y@(_:_)) -> Just (read x, read y)
    _ -> Nothing
readRXCY _ = Nothing

toAB :: Int -> String
toAB n | 0 <= n && n < 26 = [chr $ 0x41 + n]
       | otherwise = toAB (n `div` 26 - 1) ++ toAB (n `mod` 26)

readAB :: String -> (Int, Int)
readAB s = readAB' 0 s
  where
    readAB' x (c:cs)
        | isNumber c = (read $ c:cs, x)
        | otherwise = readAB' (x * 26 + ord c - 0x40) cs

main = do
    n <- fmap read getLine
    forM_ [1..n] $ \_ -> do
        line <- getLine
        case readRXCY line of
            Just (x, y) -> putStrLn $ toAB (y - 1) ++ show x
            Nothing -> let (x, y) = readAB line
                       in putStrLn $ "R" ++ show x ++ "C" ++ show y

import Data.Char
import Data.List

toAlp s 0 = s
toAlp s x = let x1 = x-1 in
    toAlp ((chr ((mod x1 26) + 65)):s) (div x1 26)

toNum x [] = x
toNum x (s:ss) = toNum (26*x + (ord s - 64)) ss

proc s = case groupBy (\x y -> isDigit x == isDigit y) s of
    [_,r,_,c] -> (toAlp [] $ read c) ++ r
    [c,r] -> "R" ++ r ++ "C" ++ (show (toNum 0 c))

main = interact $ unlines.map proc.tail.lines

import Data.Char
import Data.List
import Control.Applicative

main = do
  n <- read <$> getLine
  css <- mapM (\i -> solve n <$> getLine) [1..n]
  putStrLn $ unlines css

solve :: Int -> String -> String
solve _ cs = if isRXCY cs then fromRXCY cs
                          else toRXCY cs

isRXCY :: String -> Bool
isRXCY = not.all isDigit.dropWhile isAlpha

toRXCY :: String -> String
toRXCY cs' = "R" ++ ns ++ "C" ++ rs
   where (cs,ns) = span isAlpha cs'
         rs = show $ sum $ zipWith (*) (map (26^) [0..]) $ reverse $ map (\c->(ord c)-64) cs

fromRXCY :: String -> String
fromRXCY (c:cs) = ys' ++ xs
   where (xs,(y':ys)) = span isDigit cs
         n = sum $ zipWith (*) (map (10^) [0..]) $ reverse $ map (read.return) ys
         ys' = map (chr.(64+)) $ reverse $ to26 n

to26 :: Int -> [Int]
to26 n = if q == 0 then [r] else r:(to26 q)
   where (q,r) = divMod' n 26

divMod' x y = if r == 0 then (pred q,y) else (q,r)
   where (q,r) = divMod x y

module Main where
import Control.Monad
import Data.Char

countSeg :: String -> Integer
countSeg [] = 0
countSeg (a:[]) = 1
countSeg (a:b:c)
  |isAlpha a==isAlpha b =   countSeg(b:c)
  |otherwise            = 1+countSeg(b:c)

alphaToInt :: String -> Int -> Int
alphaToInt [] sum = sum
alphaToInt (a:b) sum = alphaToInt b (sum*26+ord a-64)

intToAlpha :: Int -> String
intToAlpha n
  | n<26      = chr (65+n) : []
  | otherwise = (intToAlpha (div n 26 - 1)) ++ ((chr (65+(mod n 26))):[])

splitAll :: String -> [String]
splitAll [] = []
splitAll s = do
  let (p:q) = s
  if isAlpha p then
    let (a,b) = splitAt (length $takeWhile isAlpha s) s in
    a:splitAll b
  else
    let (a,b) = splitAt (length $takeWhile (not.isAlpha) s) s in
    a:splitAll b

solve :: Integer -> IO ()
solve n = do
    if (n==0) then return ()
    else do
        line <- getLine
        if countSeg line == 2 then
            let (a:b:_)=splitAll line in
            putStr $"R"++b++"C"++(show $alphaToInt a 0)++"\n"
        else
            let (a:b:c:d:_)=splitAll line in
            putStr $intToAlpha (((read::String->Int) d)-1)++b++"\n"
        solve (n-1)

main = do
  buf <- getLine
  let (n:_) = map (read::String->Integer) (buf:[])
  solve n

import Control.Applicative
import Data.List
import Data.Array.Unboxed
import Data.Char

table = listArray (0, 25) ['A' .. 'Z'] :: UArray Int Char

parse xs
  | null cs   = Left (bs, as)
  | otherwise = let Left (as', bs') = parse cs in Right (bs, as') where
  (as, (bs, cs)) = span isDigit <$> span isUpper xs

numToStr :: Int -> String
numToStr n = reverse $ f n where
  f x = case (x - 1) `quotRem` 26 of
    (0 , i) -> [table ! i]
    (n', i) -> table ! i : f n'

strToNum :: String -> Int
strToNum xs = f $ reverse xs where
  f []       = 0
  f (c : cs) = (fromEnum c - fromEnum 'A' + 1) + 26 * f cs

conv xs = case parse xs of
  Left  (rs, cs) -> "R" ++ rs ++ "C" ++ show (strToNum cs)
  Right (rs, cs) -> numToStr (read cs) ++ rs

solve (n : xs) = conv <$> take (read n) xs

main = interact $ unlines . solve . lines

import Data.Char

fromAA = foldl (\s x -> s * 26 + (ord x - ord 'A' + 1)) 0

toAA x = let w x l = if x > 0 then w ((x - 1) `div` 26) (((x - 1) `mod` 26) : l) else l in
    map (\x -> chr (x + ord 'A')) $ w x []

parseLine line = map reverse $ reverse $ foldl (\ll x -> case ll of {
    l:ls | isDigit (head l) == isDigit x -> (x:l) : ls
         | True -> [x]:ll
    ; [] -> [[x]]}) [] line

conv ["R", row, "C", col] = toAA (read col) ++ row
conv [col, row] = "R" ++ row ++ "C" ++ show (fromAA col)
conv _ = undefined

main = do {
    n <-getLine
    ; mapM (\_ -> do {line <- getLine
        ; putStr $ conv $ parseLine line
        ; putChar '\n'
        }) [1..(read n)]
    }

module Main where

import Data.Char
import Control.Monad

data Cell = Cell {
  row :: Int,
  column :: Int
} deriving (Show)

showRC :: Cell -> String
showRC c = "R" <> show (row c) <> "C" <> show (column c)

showCR :: Cell -> String
showCR c = abbr (column c) <> show (row c)

radix = 26

abbr :: Int -> String
abbr x = abbr0 x ""
  where
    abbr0 0 acc = acc
    abbr0 x acc = let y = ord 'A' + ((x - 1) `mod` radix) in abbr0 ((x - 1) `div` radix) (chr y:acc)

fromAbbr :: String -> Int
fromAbbr x = fromAbbr0 x 0
  where
    fromAbbr0 [] acc = acc
    fromAbbr0 (a:xs) acc = fromAbbr0 xs $ acc * radix + (1 + ord a - ord 'A')

data Parsed = ParsedRC Cell
            | ParsedCR Cell
            | Unknown String
  deriving (Show)

split :: String -> [String]
split line = reverse $ split1 line []
  where
    split1 [] acc = acc
    split1 line acc = let (chars, rest) = break isDigit line in
      split2 rest $ chars:acc
    split2 [] acc = acc
    split2 line acc = let (digits, rest) = span isDigit line in
      split1 rest $ digits:acc

parseCell :: String -> Parsed
parseCell line = case split line of
  ["R", r, "C", c] -> ParsedRC Cell { row = read r, column = read c }
  [c, r]  -> ParsedCR Cell { row = read r, column = fromAbbr c }
  _ -> Unknown line

convert :: Parsed -> String
convert (Unknown x) = x
convert (ParsedCR c) = showRC c
convert (ParsedRC c) = showCR c

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  inputs <- replicateM n getLine
  forM_ inputs $ putStrLn . convert . parseCell

import Data.Char

isAbc123 :: String -> Bool
isAbc123 (ch:rest)
    | isAlpha ch    = isAbc123 rest
    | otherwise     = and $ map isDigit rest

an2rc :: String -> String
an2rc an = "R" ++ rowStr ++ "C" ++ (show $ excel2Num 0 colExcel)
            where
                splitAbc123 cur whole@(ch:rest)
                    | isDigit ch    = (cur, whole)
                    | otherwise     = splitAbc123 (cur++[ch]) rest
                (colExcel, rowStr) = splitAbc123 "" an
                excel2Num acc ""        = acc
                excel2Num acc (ch:rest) = excel2Num (acc*26+ord(ch)-ord('A')+1) rest

rc2an :: String -> String
rc2an rc = (excelNota col) ++ rowStr
            where
                stripNums cur (ch:rest)
                    | ch == 'R' = stripNums cur rest
                    | ch == 'C' = (cur, rest)
                    | otherwise = stripNums (cur++[ch]) rest
                (rowStr, colStr) = stripNums "" rc
                col = read colStr :: Int
                excelNota 0 = ""
                excelNota n = (excelNota $ (n-1) `div` 26) ++ [chr $ (n-1) `mod` 26 + ord('A')]

convert :: String -> String
convert s
    | isAbc123 s    = an2rc s
    | otherwise     = rc2an s

main :: IO ()
main = do
    t <- (read :: String -> Int) <$> getLine
    run t
        where
            run 0   = return ()
            run n   = do
                coord <- getLine
                putStrLn $ convert coord
                run (n-1)

{-# OPTIONS_GHC -O2 #-}

import Data.Char
import Data.List

splitVia l h = go []
  where go acc [] = (reverse acc, [])
        go acc r@(c:cs) | o >= l && o <= h = go (c:acc) cs
                        | otherwise        = (reverse acc,r)
          where o = ord c

f26 = show . foldl' f 0
      where f a c = (ord c - 64) + a*26

t26 n = go [] $ n - 1
  where go acc m | m < 0 = acc
                 | otherwise = go ((chr $ m `rem` 26 + 65) : acc) (m `quot` 26 - 1)

transform s0 | a == "R" && c == "C" = (t26 $ read d) ++ b
             | null c   && null d   = "R" ++ b ++ "C" ++ (f26 a)
  where (a, s1) = splitVia 65 90 s0
        (b, s2) = splitVia 48 57 s1
        (c, s3) = splitVia 65 90 s2
        (d, s4) = splitVia 48 57 s3

main = interact (unlines . map transform . tail . lines)

{-# OPTIONS_GHC -O2 #-}

import Data.Char

abc = ['A'..'Z']
ztn = ['0'..'9']

splitVia ps = go []
  where go acc [] = (reverse acc, [])
        go acc r@(l:ls) | l `elem` ps = go (l:acc) ls
                        | otherwise   = (reverse acc,r)

f26 = show . foldl f 0
      where f a c = (ord c - 64) + a*26

t26 n = go [] $ n - 1
  where go acc m | m < 0 = acc
                 | otherwise = go ((chr $ m `rem` 26 + 65) : acc) (m `quot` 26 - 1)

transform s0 | a == "R" && c == "C" = (t26 $ read d) ++ b
             | null c   && null d   = "R" ++ b ++ "C" ++ (f26 a)
  where (a, s1) = splitVia abc s0
        (b, s2) = splitVia ztn s1
        (c, s3) = splitVia abc s2
        (d, s4) = splitVia ztn s3

main = interact (unlines . map transform . tail . lines)

import Data.Char

abc = ['A'..'Z']
ztn = ['0'..'9']

splitVia ps = go []
  where go acc [] = (reverse acc, [])
        go acc r@(l:ls) | l `elem` ps = go (l:acc) ls
                        | otherwise   = (reverse acc,r)

f26 = show . foldl f 0
      where f a c = (ord c - 64) + a*26

t26 n = go [] $ n - 1
  where go acc m | m < 0 = acc
                 | otherwise = go ((chr $ m `rem` 26 + 65) : acc) (m `quot` 26 - 1)

transform s0 | a == "R" && c == "C" = (t26 $ read d) ++ b
             | null c   && null d   = "R" ++ b ++ "C" ++ (f26 a)
  where (a, s1) = splitVia abc s0
        (b, s2) = splitVia ztn s1
        (c, s3) = splitVia abc s2
        (d, s4) = splitVia ztn s3

main = interact (unlines . map transform . tail . lines)

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
import Data.Char
import Data.List
class Scan a where scan' :: String -> a
instance Scan Int where scan' n = read n
instance Scan Char where scan' (x:_) = x
instance Scan Float where scan' f = read f
instance Scan Double where scan' d = read d
instance Scan Integer where scan' n = read n
instance Scan String where scan' x = x
instance (Scan a,Scan b) => Scan (a,b) where scan' x = scan'' (words x)
                                                 where
                                                   scan'' (x:y:_) = (scan' x,scan' y)
instance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = scan'' (words x)
                                                          where
                                                            scan'' (x:y:z:_) = (scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = scan'' (words x)
                                                                   where
                                                                     scan'' (w:x:y:z:_) = (scan' w,scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = scan'' (words x)
                                                                            where
                                                                              scan'' (v:w:x:y:z:_) = (scan' v,scan' w,scan' x,scan' y,scan' z)
class Ans a where showans :: a -> String
instance Ans Int where showans x = show x
instance Ans Char where showans x = [x]
instance Ans Float where showans x = show x
instance Ans Double where showans x = show x
instance Ans Integer where showans x = show x
instance Ans String where showans x = x
instance (Ans a, Ans b) => Ans (a,b) where
    showans (x,y) = showans x ++ " " ++ showans y
instance (Ans a, Ans b,Ans c) => Ans (a,b,c) where
    showans (x,y,z) = showans x ++ " " ++ showans y ++ " " ++ showans z

scan :: (Scan a) => IO a
scan = do n <- getLine
          return (scan' n)

scans :: (Scan a) => Int -> IO [a]
scans 0 = return []
scans n = do x <- scan
             xs <- scans (n-1)
             return (x:xs)

scanlist :: (Scan a) => IO [a]
scanlist = do l <- getLine
              return [scan' x|x<-words l]

scanlists :: (Scan a) => Int -> IO [[a]]
scanlists 0 = return []
scanlists n = do x <- scanlist :: (Scan a) => IO [a]
                 xs <- scanlists (n-1)
                 return (x:xs)

putAnsLn :: (Ans a) => a -> IO ()
putAnsLn ans = putStrLn (showans ans)

putAnsLns :: (Ans a) => [a] -> IO ()
putAnsLns (x:xs) = do putAnsLn x
                      putAnsLns xs
putAnsLns [] = return ()

putDebugLn :: (Show a) => a -> IO ()
putDebugLn ans = putStrLn (show ans)

inRange :: Ord a => (a,a) -> a -> Bool
inRange (n,m) x = n<=x&&x<=m

isExcel :: String -> Bool
isExcel = null.(dropWhile isDigit).(dropWhile isAlpha)

exceltoRC :: String -> String
exceltoRC str = let (c',r) = span (inRange ('A','Z')) str in
                let c = foldl (\s -> \c -> (ord c)-(ord 'A')+1+s*26) 0 c' in
                ('R':r)++('C':(show c))

rctoExcel :: String -> String
rctoExcel (_:str) = let (r,(_:c')) = span (inRange ('0','9')) str in
                    let c = unfoldr (\x -> if x==0 then Nothing else Just (chr ((mod (x+25) 26)+(ord 'A')),div x 26 + (if mod x 26 == 0 then -1 else 0))) (read c'::Int) in
                    (reverse c)++r

solve [] = []
solve (x:xs) = (if isExcel x then exceltoRC x else rctoExcel x):solve xs

main = do n <- scan :: IO Int
          l <- scans n ::IO [String]
          putAnsLns (solve l)

import Control.Monad
import Data.Char
import Data.List
import System.IO

s2i = foldl (\a x -> 26*a + ord x - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = do
	hSetBuffering stdin (BlockBuffering (Just 32768))
	interact $ unlines . map conv . tail . lines

import Data.Char
import Data.List

s2i = foldl (\s d -> 26*s + ord d - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = interact $ unlines . map conv . tail . lines

import Data.Char

isRC s = s !! 0 == 'R' && isDigit (s !! 1) && 'C' `elem` s

from26 [] = 0
from26 (d:ds) = (ord d - ord 'A' + 1) * 26 ^ length ds + from26 ds

toRC s = "R" ++ y ++ "C" ++ show (from26 x) where (x, y) = span isUpper s

to26 0 = []
to26 a = [chr (ord 'A' + (a - 1) `mod` 26)] ++ (to26 $ (a - 1) `div` 26)

toXY s = reverse (to26 c) ++ show r where [r, c] = map read . words $ map (\c -> if isDigit c then c else ' ') s

conv s = if isRC s then toXY s else toRC s

main = interact $ unlines . map conv . drop 1 . lines

import Control.Monad
import Data.Char
import Data.List
import System.IO

s2i = foldl (\a x -> 26*a + ord x - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = do
	hSetBuffering stdin (BlockBuffering (Just 4096))
	interact $ unlines . map conv . tail . lines

import Control.Monad
import Data.Char
import Data.List

s2i = foldl (\a x -> 26*a + ord x - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

-- main = interact $ unlines . map conv . tail . lines

main = do
	n <- fmap read getLine
	forM_ [1..n] $ \_ -> do
		l <- getLine
		putStrLn (conv l)

import Control.Monad
import Data.Char
import Data.List
import System.IO

s2i = foldl (\a x -> 26*a + ord x - ord 'A' + 1) 0

i2s 0 = []
i2s a = chr (ord 'A' + (a - 1) `mod` 26) : (i2s $ (a - 1) `div` 26)

conv s =
	case groupBy (\a b -> isDigit a == isDigit b) s of
		[_, r, _, c] -> (reverse . i2s . read $ c) ++ r
		[c, r] -> "R" ++ r ++ "C" ++ (show . s2i $ c)

main = interact $ unlines . map conv . tail . lines

import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    n <- readInt
    inputs <- replicateM n getLine
    mapM_ putStrLn $ parseInputs inputs

parseInputs :: [String] -> [String]
parseInputs [] = []
parseInputs (x:xs) = [spreadSheets x] ++ parseInputs xs

spreadSheets :: String -> String
spreadSheets s = case xs of
    [_,r,_,c] -> rc (read r) (read c)
    [c,r]     -> cr c (read r)

    where xs = groupBy(\a b -> (isDigit a && isDigit b) || (isAlpha a && isAlpha b)) s

cr :: String -> Int -> String
cr c r = "R" ++ (show r) ++ "C" ++ show (conv c)

conv :: String -> Int
conv [] = 1
conv (r:[]) = ord r - ord 'A' + 1
conv (r:rs) = 26^(length rs) * (ord r - ord 'A' + 1) + conv rs

rc :: Int -> Int -> String
rc r c = (inv c) ++ show r

inv :: Int -> String
inv 0 = ""
inv a = inv ((a - 1) `div` 26) ++ [chr (ord 'A' + (a - 1) `mod` 26)]

readInt :: IO Int
readInt = readLn

import Control.Monad
import Data.Char
import Data.List
import Data.Maybe
import Debug.Trace

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

mapX :: a -> [a -> b] -> [b]
mapX _ [] = []
mapX x (f:fs) = [f x] ++ (mapX x fs)

map2 :: (a -> b -> c) -> [a] -> [b] -> [c]
map2 _ [] [] = []
map2 f (ax:axs) (bx:bxs) = [f ax bx] ++ map2 f axs bxs

isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _  = False

all' :: (a -> Bool) -> [a] -> Bool
all' _ [] = False
all' f l  = all f l

splitByPredicate :: (a -> Bool) -> [a] -> [[a]]
splitByPredicate _ [] = []
splitByPredicate p l
    | p (head l) == True = [takeWhile p l] ++ (splitByPredicate p (dropWhile p l))
    | otherwise          = [takeWhile (not . p) l] ++ (splitByPredicate p (dropWhile (not . p) l))

type CellType = Int

checkCellType :: String -> CellType
checkCellType s
    | length (splitByPredicate isDigit s) == 4 = 1
    | length (splitByPredicate isDigit s) == 2 = 2
    | otherwise                                = error "wrong string!"

fastExp :: Int -> Int -> Int
fastExp x 0 = 1
fastExp x 1 = x
fastExp x a
    | even a     = lexp * lexp
    | odd a      = lexp * lexp * x
    where
        lexp = fastExp x (div a 2)

colStr2Inth :: String -> Int
colStr2Inth [] = 0
colStr2Inth s  = (colStr2Inth $ init s) * 26 + (ord (last s) - ord 'A')

colStr2Int :: String -> Int
colStr2Int s = sum (map (fastExp 26) [0 .. (length s - 1)]) + colStr2Inth s

convertCellType2To1 :: String -> String
convertCellType2To1 s =
    let sp = splitByPredicate isDigit s
    in "R" ++ (sp !! 1) ++ "C" ++ (show $ colStr2Int (sp !! 0))

colInt2Strhh :: Int -> String
colInt2Strhh n
    | n < 26    = [chr (ord 'A' + n)]
    | otherwise = (colInt2Strhh (div n 26)) ++ (colInt2Strhh (mod n 26))

colInt2Strh :: Int -> Int -> String
colInt2Strh n l =
    let hresult = colInt2Strhh n
    in (replicate (l - length hresult)) 'A' ++ hresult

colInt2Str :: Int -> String
colInt2Str n =
    let powList = map (fastExp 26) [0 .. 100]
        sumPowList = scanl1 (+) powList
        fi = fromJust (findIndex (<0) (map2 (-) (replicate 100 n) sumPowList))
    in colInt2Strh (n - (sumPowList !! (fi - 1))) (fi)

convertCellType1To2 :: String -> String
convertCellType1To2 s =
    let sp = splitByPredicate isDigit s
    in colInt2Str (read (sp !! 3) :: Int) ++ (sp !! 1)

convertCellType :: String -> String
convertCellType s
    | checkCellType s == 1 = convertCellType1To2 s
    | checkCellType s == 2 = convertCellType2To1 s

main = do
   {- putStrLn $ show $ fastExp 26 2-}
  {-  putStrLn $ show $ fastExp 26 3
    putStrLn $ show (scanl1 (+) (map (fastExp 26) [0 .. 20]))
    putStrLn $ show $ colStr2Inth "AUHS"-}
    sn <- getLine
    let n = read sn :: Int
    sl <- getLines n
    putStrLn $ unlines (map convertCellType sl)

import Data.Char
import Data.List

main = interact $ unlines . map conv . tail . lines

conv s = to arr
    where arr = groupBy (\a b -> isDigit a == isDigit b) s

rc (ch:s) = ch == 'R'

to [c, r] = "R" ++ r ++ "C" ++ (show . toRCcolumn $ c)
to [_, r, _, c] = (reverse . toXYcolumn . read $ c) ++ r

toRCcolumn = foldl (\acc d -> 26 * acc + ord d - ord 'A' + 1) 0

toXYcolumn 0 = []
toXYcolumn c = (chr (cmod + ord 'A')) : toXYcolumn cdiv
    where (cdiv, cmod) = (c - 1) `divMod` 26

import Data.Char
import Data.List

main = interact $ unlines . map conv . tail . lines

conv s = to arr
    where arr = groupBy (\a b -> isDigit a == isDigit b) s

to [c, r] = "R" ++ r ++ "C" ++ (show . toRCcolumn $ c)
to [_, r, _, c] = (reverse . toXYcolumn . read $ c) ++ r

toRCcolumn = foldl (\acc d -> 26 * acc + ord d - ord 'A' + 1) 0

toXYcolumn 0 = []
toXYcolumn c = (chr $ cmod + ord 'A') : toXYcolumn cdiv
    where (cdiv, cmod) = (c - 1) `divMod` 26

{-# LANGUAGE ScopedTypeVariables #-}
module Main where

import Data.List
import Data.Char

letters = map (\x -> chr (ord 'A' + (x - 1) `mod` 26)) . reverse . takeWhile (>0) . iterate (\x -> (x-1) `div` 26)
numbers = sum . zipWith (*) (iterate (*26) 1) . reverse . map (\x -> ord x - ord 'A' + 1)

convert :: [String] -> String
convert ("R":r:"C":c:[]) = letters (read c) ++ r
convert (c:r:[]) = "R" ++ r ++ "C" ++ show (numbers c)

main = do
    (n :: Int,cells) <- getContents >>= return . (\(n:cells) -> (read n,map (map toUpper) cells)) . lines
    mapM (putStrLn . convert . groupBy (\l r -> isDigit l == isDigit r)) (take n cells)

{- Format 1 is letters for columns and numbers for the row.
 - eg. BC23 -}
import Data.Char
import qualified Data.Map.Strict as Map
import Data.Maybe
import System.IO
import Data.List

reverseColumnMap = Map.fromList $ zip letters [1..1000000]

letters = (map (\x -> [x]) gen) ++ (next $ (map (\x -> [x]) gen))
          where gen = ['A'..'Z']
                next list = this ++ (next this)
                  where this = concat $ map (\x -> map (x:) list) gen

encode1 :: (Int, Int) -> String
encode1 (row, col) = convertCol col ++ (show row)
convertCol c = toLetters $ pad $ toBase26 $ (c - offset)
  where offset = sum $ map (26^) [1..lim-1]
        lim = limit c
        limit x = fromJust $ findIndex (>=x) limits
        limits = scanl (+) 0 (map (26^) [1..])
        toBase26 x = fromBase10 (x - 1) 26
        pad xs = if length xs < lim then pad (0:xs) else xs
        toLetters = map (chr.(+(ord 'A')))
        fromBase10 :: (Integral a) => a -> a -> [a]
        fromBase10 n base = reverse $ fromBase10Reversed n base
          where
            fromBase10Reversed :: (Integral a) => a -> a -> [a]
            fromBase10Reversed n base
             | n < base     = [n]
             | otherwise    = firstDigit:(fromBase10Reversed rest base)
                where firstDigit = (n `rem` base)
                      rest = (n `div` base)

decode1 :: (String) -> (Int, Int)
decode1 string = let (letters, numbers) = split string
                 in ((read numbers)::Int, parse letters)
                 where split [] = ("", "")
                       split (x:xs) = if (isAlpha x)
                                      then (x:(fst next), snd next)
                                      else ("", x:xs)
                                      where next = split xs

parse l = (toBase10 (toNumbers l) 26) + offset
  where offset = 1 + (sum $ map (26^) [1..(length l) - 1])
        toBase10 :: (Integral a) => [a] -> a -> a
        toBase10 n base = sum $ map (\(a, b) -> (base^a) * b) (placeValuePairs n)
            where
              placeValuePairs :: (Integral a) => [a] -> [(a, a)]
              placeValuePairs digits = zip placeCount digits
                                      where placeCount = [len - 1, len - 2..0]
                                            len = fromIntegral $ length digits
        toNumbers l = map ((+ (-(ord 'A'))).ord) l

encode2 :: (Int, Int) -> String
encode2 (row, col) = "R" ++ (show row) ++ "C" ++ (show col)

decode2 (x:xs) = let (firstNum, remaining) = getFirstNum xs
                 in ((read firstNum)::Int, (read $ tail remaining)::Int)
                 where getFirstNum (y:ys) = if isDigit y
                                            then ((y : (fst next)), snd next)
                                            else ("", y:ys)
                                            where next = getFirstNum ys

process :: String -> String
process xs = if type2
             then encode1 $ decode2 xs
             else encode2 $ decode1 xs
             where type2 = (isDigit (xs !! 1)) && ('C' `elem` (tail xs))

f :: String -> IO Int
f string = return ((read string)::Int)

main = do
         hGetLine stdin
         inpStr <- hGetContents stdin
         let toProcess = lines inpStr
         putStr $ unlines $ map process toProcess

module Main where

import Control.Monad
import Control.DeepSeq
import Data.Function
import Data.List
import Data.Char

--import Debug.Trace

type AlphaNum = String -- little endian

str2an = reverse
an2str = reverse

data Numeration = T1 String Int | T2 Int Int

instance Show Numeration where
    show (T1 col row) = col ++ show row
    show (T2 row col) = "R" ++ show row ++ "C" ++ show col

isT2 (r:x:cy) = (r == 'R') && isDigit x && ('C' `elem` cy)
isT2 _ = False

toT1 str = T1 col (read row) where
    (col, row) = span isLetter str

toT2 str = T2 (read row) (read col) where
    (r:row, c:col) = span ((/=) 'C') str

convertType (T1 col row) = T2 row (atoi col)
convertType (T2 row col) = T1 (itoa col) row

-- 'i' is 0-index
atoi [] = 0
atoi str = (ord x - ord 'A' + 1) + (26 * atoi xs) where
    x = last str
    xs = init str

itoc i = chr (ord 'A' + i - 1)
itoa i = if q' == 0 then [itoc r'] else itoa q' ++ [itoc r'] where
    (q, r) = i `divMod` 26
    (q', r') = if r == 0 then (q-1, 26) else (q, r)

process :: String -> String
process str = show numeration' where
    numeration = if isT2 str then toT2 str else toT1 str
    numeration' = convertType numeration

printLines = fmap head . sequence . map putStrLn

main = do
    n <- read <$> getLine
    lines <- replicateM n getLine
    printLines (map process lines)

module Main where
--module Test where
import System
import Data.Char
import Data.List
import Control.Monad
import Control.Applicative

main = do line <- getLine
          let n = read line :: Int
          run_testcase n
          return ()

tonum c = ord c - ord 'A'

convert_to_index [c] = tonum c

-- A -> 0
-- AA -> 26
-- AB -> 27
convert_to_index (x:xs) = (tonum x) + ((convert_to_index xs) + 1) * 26

convert_to_str num
    | num < 26 = [chr $ num + ord 'A']
    | otherwise = convert_to_str (num `div` 26 - 1) ++ [chr ((num `mod` 26) + ord 'A')]

is_rc_format str = (check rs 'R') && (check cs 'C')
    where
      (rs,cs) = break ('C'==) str
      check token c = length token >= 2 && head token == c && all isDigit (tail token)

solve2 str
    | is_rc_format(str) =
        let (rs,cs) = break ('C'==) str
            r = tail rs
            c = read $ tail cs :: Int
        in
          convert_to_str(c - 1) ++ (r)
    | otherwise =
        let (c,r) = break isDigit str
        in
          "R" ++ r ++ "C" ++ show ((convert_to_index $ reverse c) + 1)

run_testcase 0 = do return ()
run_testcase n =
    do
      line <- getLine
      putStrLn $ solve2 line
      run_testcase (n-1)
      return ()

import Data.Char
import Data.List

intToStr 0 = []
intToStr x = chr ( ( x - 1 ) `mod` 26 + ord 'A' ) : intToStr ( ( x - 1 ) `div` 26 )

strToInt = foldl ( \ x y -> 26 * x + ord y - ord 'A' + 1 ) 0

solve str =
	case parse str of
		[_,r,_,c] -> ( reverse . intToStr . read $ c ) ++ r
		[c,r] -> "R" ++ r ++ "C" ++ ( show . strToInt $ c )
	where parse = groupBy ( \ a b -> isDigit a == isDigit b )

main = interact $ unlines . map solve . tail . lines

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n == 0 = ""
  | otherwise = n2a (m `div` 26) ++ [c (m `mod` 26)]
  where
    m = n - 1
    c x = chr (ord 'A' + x)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.List
intToStr 0 = []
intToStr x = (intToStr $ (x - 1) `div` 26) ++ [chr $ (x - 1) `mod` 26 + ord 'A']
strToInt = foldl (\ s c -> 26 * s + ord c - ord 'A' + 1) 0
f str = case parse str of
            [_,r,_,c] -> (intToStr . read $ c) ++ r
            [c,r] -> "R" ++ r ++ "C" ++ (show . strToInt $ c)
        where
            parse = groupBy (\a b -> isDigit a == isDigit b)
main = interact $ unlines . map f . tail . lines

import Data.Char
import Data.Function
import Data.List

fromBase26 :: String->Int
-- 64 = 'A' - 1
fromBase26 s = foldl (\acc c->acc*26 + ord c -64) 0 s

toBase26::Int->String
toBase26 i = if i == 0
             then []
             else  toBase26 ((i - 1) `div` 26) ++ return (chr ((i-1) `mod` 26 + 65))

parseSplit input = groupBy ((==) `on` isAlpha) input

transform :: [String] -> String
transform [_, r, _, c] = toBase26  (read c::Int) ++ r
transform [c, r] = "R" ++ r ++ "C" ++ show (fromBase26 c)

act :: IO()
act = do
    s<-getLine
    putStrLn $ transform $ parseSplit s

main = do
    s<-getLine
    let testNum = read s::Int
    mapM_ (\x->act) $take testNum[1..]
    return ()

import Data.Char
import Data.Function
import Data.List

fromBase26 :: String->Int
-- 64 = 'A' - 1
fromBase26 s = foldl (\acc c->acc*26 + ord c - 64) 0 s

toBase26::Int->String
toBase26 0 = []
toBase26 i = toBase26 ((i - 1) `div` 26) ++ [chr ((i-1) `mod` 26 + 65)]

parseSplit input = groupBy ((==) `on` isAlpha) input

transform :: [String] -> String
transform [_, r, _, c] = (toBase26.read) c ++ r
transform [c, r] = "R" ++ r ++ "C" ++ show (fromBase26 c)

main = do
    --Skip the first line
    s<-getLine
    interact $ unlines.map (transform.parseSplit).lines

{-# LANGUAGE FlexibleInstances #-}
module Main (printShit, printShitV, readShit, main) where
import Data.ByteString.Builder
import qualified Data.ByteString.Lazy.Char8 as BS
import Data.Maybe
import Data.Char

-- Meat
solve :: [String] -> [String]
solve = fmap (disp . convert . parse)
    where
        convert c@(ExcelCell _ _) = getLotus $ toCanonical  c
        convert c@(LotusCell _ _ ) = getExcel $ toCanonical c

data Cell =  ExcelCell String Int | LotusCell Int Int deriving (Show)

disp :: Cell -> String
disp (ExcelCell col row) = col ++ show row
disp (LotusCell row col) = "R" ++ show row ++ "C" ++ show col

parse :: String -> Cell
parse s
    | null rrs = ExcelCell initAlpha (read initNum)
    | otherwise = LotusCell (read initNum) (findColumn rrs)
    where (initAlpha, rs) = span isAlpha s
          (initNum, rrs) = span isDigit rs
          findColumn :: String -> Int
          findColumn = read . dropWhile isAlpha

toCanonical :: Cell -> (Int, Int)
toCanonical (LotusCell row col) = (row, col)
toCanonical (ExcelCell col row) = (row, aTN col)

getExcel :: (Int, Int) -> Cell
getExcel (r, c) = ExcelCell (nTA c) r

getLotus :: (Int, Int) -> Cell
getLotus (r, c) = LotusCell r c

aTN :: String -> Int
aTN [x] = ord x - ord 'A' + 1
aTN (x:xs) = prelim * aTN[x] + aTN xs
    where prelim = aTN (replicate (l - 1) 'Y' ++ "Z")
          l = length xs
aTN [] = error "You suck"

nTA :: Int -> String
nTA n
    | n <= 26 = [chr (64 + n)]
    | r == 0 = nTA (q - 1) ++ "Z"
    | otherwise = nTA q ++ nTA r
         where (q, r) = n `quotRem` 26

-- Shit
main :: IO ()
main = do
        _:xs <- readShit
        printShitV $ solve xs

class Shit a where
    printShit :: a -> IO ()
    printShitV :: a -> IO ()
    readShit :: IO a
    printShitV = printShit

instance  Shit Int where
    printShit = print
    readShit = fmap read getLine

instance  Shit [Int] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance  Shit [Integer] where
    printShit = putStrLn . unwords . fmap show
    printShitV = putStrLn . unlines . fmap show
    readShit = fmap (fmap read . words) getLine

instance Shit [[Int]] where
    printShit = printShit . (fmap.fmap)  (toLazyByteString . integerDec .toInteger)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [[Integer]] where
    printShit  = printShit . (fmap.fmap)  (toLazyByteString . integerDec)
    readShit = fmap (fmap.fmap $ fromInteger.fst.fromJust. BS.readInteger) readShit

instance Shit [String] where
    printShit = putStrLn. unwords
    printShitV = putStrLn . unlines
    readShit = fmap lines getContents

instance Shit [[String]] where
    printShit = putStrLn . unlines . fmap unwords
    readShit = fmap (fmap (fmap words) lines) getContents

instance Shit [BS.ByteString] where
    printShit = BS.putStrLn. BS.unwords
    printShitV = BS.putStrLn . BS.unlines
    readShit = fmap BS.lines BS.getContents

instance Shit [[BS.ByteString]] where
    printShit = BS.putStrLn . BS.unlines . fmap BS.unwords
    readShit = fmap (fmap (fmap BS.words) BS.lines) BS.getContents

import Data.Char

data CharType = Alpha | Digit | Unknown
  deriving (Eq)

data CellFormat = ABC123 | RXCY
  deriving (Show)
data CellRef = CellRef {
  row :: Integer,
  column :: Integer
} deriving (Show)

charType :: Char -> CharType
charType c | isDigit c = Digit
           | isAlpha c = Alpha
           | otherwise = Unknown

stringType :: String -> CharType
stringType s = charType (head s)

split :: String -> [String]
split s = reverse (split2 s [])

split2 :: String -> [String] -> [String]
split2 [] xs = xs
split2 (c:cs) [] = split2 cs [[c]]
split2 (c:cs) (x:xs) | charType c == charType (head x) = split2 cs ((x ++ [c]):xs)
                     | otherwise = split2 cs ([c]:x:xs)

readColumnRef :: String -> Integer
readColumnRef s = readColumnRef2 0 s
  where readColumnRef2 v [] = v
        readColumnRef2 v (x:xs) = readColumnRef2 (v*26 + toInteger (ord (toUpper x) - ord 'A' + 1)) xs

showColumnRef :: Integer -> String
showColumnRef x = showColumnRef2 "" x
  where showColumnRef2 :: String -> Integer -> String
        showColumnRef2 [] 0 = "A"
        showColumnRef2 s 0 = s
        showColumnRef2 s x = showColumnRef2 ([chr ((fromIntegral ((x-1) `mod` 26)) + ord 'A')] ++ s) ((x-1) `div` 26)

readCellRef :: String -> (CellRef, CellFormat)
readCellRef s = case (split s) of
  ("R":x:"C":y:[]) ->
    (CellRef (read x) (read y), RXCY)
  (a:x:[]) | (stringType a == Alpha) && (stringType x == Digit) ->
    (CellRef (read x) (readColumnRef a), ABC123)
  _ -> error "Invalid cell reference format"

showCellRef :: CellRef -> CellFormat -> String
showCellRef c ABC123 = (showColumnRef (column c)) ++ (show (row c))
showCellRef c RXCY = "R" ++ (show (row c)) ++ "C" ++ (show (column c))

convert :: String -> String
convert s = case (readCellRef s) of
    (c, ABC123) -> showCellRef c RXCY
    (c, RXCY) -> showCellRef c ABC123

solve :: IO ()
solve = getLine >>= (putStrLn . convert)

solveN :: Int -> IO ()
solveN 1 = solve
solveN n = do
  solve
  solveN (n-1)

main = getLine >>= (solveN . read)

{-
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.
=====================
-}
import Data.List(groupBy)
import Data.Char(chr,isDigit,ord)

equatingDigits a b = isDigit a == isDigit b

isRC :: String -> Bool
isRC = (==4) . length . groupBy equatingDigits

readNLines :: Int -> IO [String]
readNLines 1 = do
  line <- getLine
  return [line]
readNLines n = do
  line <- getLine
  moreLines <- readNLines (n-1)
  return $ line:moreLines

convert :: String -> String
convert s = if isRC s
            then rcToA1 s
            else a1ToRc s
  where rcToA1 s = case groupBy equatingDigits s of
          [_,r,_,c] ->(toB26 $ read c) ++ r
        a1ToRc s = case groupBy equatingDigits s of
          [c,r] -> ('R':(init $ tail $ show r)) ++ ('C':show (fromB26 c))
toB26 :: Int -> String
toB26 x = case pred x `div` 26 of
  0 -> [chr $ x + 64]
  n -> toB26 n ++ (toB26 $ succ $ pred x `mod` 26)

fromB26 [c] = ord c - 64
fromB26 (c:cs) = (ord c - 64) * 26 ^ length cs + fromB26 cs

main = do
  n <- getLine
  input <- readNLines (read n)
  mapM (putStrLn . convert) input

module Main where

import Data.Char (isAlpha, isDigit)
import Data.List (groupBy, elemIndex)

getInt :: IO Int
getInt = readLn

processInput :: Int -> String -> String
processInput n = unlines . map processLine . take n . lines

processLine :: String -> String
processLine line = case groupBy (\a b -> isSep a b) line of
  [_, r, _, c] -> convert (read c) ++ r
  [c, r] -> "R" ++ r ++ "C" ++ (show $ unconvert c)
  where isSep a b = not $ (isAlpha a) && (isDigit b) || (isDigit a) && (isAlpha b)

convert :: Int -> String
convert n = if n <= 26
  then [['A'..'Z'] !! (n - 1)]
  else case quotRem n 26 of
    (q, r) -> if r /= 0
      then (convert q) ++ (convert r)
      else (convert (q - 1)) ++ "Z"

unconvert = foldl go 0
  where go prev c = case elemIndex c ['A'..'Z'] of Just n -> prev * 26 + n + 1

main = do
  n <- getInt
  interact $ processInput n

import Control.Monad
import Data.Char
import Text.Printf

toAlphabetic :: Int -> String
toAlphabetic 0 = ""
toAlphabetic n =
    let quotient = n `div` 26
        remainder = n `mod` 26
        current = chr $ (ord 'A') + remainder - 1
        recur = toAlphabetic quotient
    in recur ++ [current]

toFirstForm :: String -> String -> String
toFirstForm r c' =
    let c = toAlphabetic $ read c'
    in c ++ r

toDigit :: String -> Int
toDigit = foldl (\accum current -> accum * 26 + (ord current - ord 'A' + 1)) 0

toSecondForm :: String -> String -> String
toSecondForm r c = "R" ++ c ++ "C" ++ (show $ toDigit r)

transform :: [String] -> String
transform [_, r, _, c] = toFirstForm r c
transform [r, c] = toSecondForm r c

splitByAlphaNumber :: [String] -> Char -> [String]
splitByAlphaNumber [] current = [[current]]
splitByAlphaNumber parsed current =
    let lastElement = last parsed
        lastLetter = last lastElement
    in if isDigit lastLetter == isDigit current
        then (init parsed) ++ [lastElement ++ [current]]
        else parsed ++ [[current]]

parseInput :: String -> [String]
parseInput = foldl splitByAlphaNumber []

solve :: String -> String
solve = transform . parseInput

readInput _ = do
    input <- getLine
    return input

main = do
    input <- getLine
    let n = read input :: Int
    inputs <- forM [1..n] readInput
    forM inputs $ (printf "%s\n") . solve

module Main (main)
    where

import Data.List (foldl', unfoldr)
import Data.Tuple (swap)
import Data.Char (ord, chr, isAsciiUpper, isDigit)
import Control.Monad (replicateM)

toCartesian :: String -> String
toCartesian xs = 'R':row ++ 'C':show col
    where (q,row) = span isAsciiUpper xs
          col = foldl' (\r c -> 26 * r + ord c - ord 'A' + 1) 0 q

toExcel :: String -> String
toExcel (_:xs) = col ++ row
    where (row,_:ccol) = span isDigit xs
          col = reverse . map toChar . go $ read ccol
          go 0 = []
          go n = let (q,r) = divMod n 26 in r:go q
          toChar 0 = 'Z'
          toChar n = chr $ ord 'A' + n - 1

main :: IO ()
main = putStr . unlines . map solve =<< flip replicateM getLine =<< readLn
    where solve xs
            | all isDigit $ dropWhile isAsciiUpper xs = toCartesian xs
            | otherwise = toExcel xs

module Main (main)
    where

import Data.List (foldl', unfoldr)
import Data.Tuple (swap)
import Data.Char (ord, chr, isAsciiUpper, isDigit)
import Control.Monad (replicateM)

toCartesian :: String -> String
toCartesian xs = 'R':row ++ 'C':show col
    where (q,row) = span isAsciiUpper xs
          col = foldl' (\r c -> 26 * r + ord c - ord 'A' + 1) 0 q

toExcel :: String -> String
toExcel (_:xs) = col ++ row
    where (row,_:ccol) = span isDigit xs
          col = reverse [chr $ ord 'A' + i - 1 | i <- unfoldr go $ read ccol]
          go 0 = Nothing
          go n = Just . swap $ divMod n 26

main :: IO ()
main = putStr . unlines . map solve =<< flip replicateM getLine =<< readLn
    where solve xs
            | all isDigit $ dropWhile isAsciiUpper xs = toCartesian xs
            | otherwise = toExcel xs

import Data.Char

main = do
	n<-getLine
	reading (read n) []

reading 0 buf = do
	mapM putStrLn $ lines buf
reading a buf = do
	s<-getLine
	reading (a-1) $ buf++pars s ++"\n"

pars s
 | s=="" = ""
 | head s == 'R' && length s>=2 && isDigit (s!!1) && elem 'C' s = (numberToLetters (read (tail cPart)))
                                  ++ rPart
 | otherwise = "R"++sPart++ "C" ++  ( show (lettersToNumber fPart))
                where  rPart = (takeWhile isDigit (tail s))
                       cPart = dropWhile isDigit (tail s)
                       fPart = takeWhile (not.isDigit) s
                       sPart = dropWhile (not.isDigit) s

lettersToNumber::String->Integer
lettersToNumber []= 0
lettersToNumber s = toInteger (ord (head s)-ord 'A'+1) * 26^(length s-1)+ (lettersToNumber $ tail s)

numberToLetters::Integer->String
numberToLetters 0 = ""
numberToLetters n
  | mod n 26==0 = reverse$"Z" ++ (numberToLetters  (div n 26-1))
  | otherwise   = reverse$ [chr (fromIntegral (mod n 26 + fromIntegral( ord 'A')-1))]
                  ++ reverse (numberToLetters $ div n 26)

import Data.Char

main = do
    n<-getLine
    reading (read n) []

reading 0 buf = do
    mapM putStrLn $ lines buf
reading a buf = do
    s<-getLine
    reading (a-1) $ buf++pars s ++"\n"

pars s
 | s=="" = ""
 | head s == 'R' && length s>=2 && isDigit (s!!1) && elem 'C' s = (numberToLetters (read (tail cPart)))
                                  ++ rPart
 | otherwise = "R"++sPart++ "C" ++  ( show (lettersToNumber fPart))
                where  rPart = (takeWhile isDigit (tail s))
                       cPart = dropWhile isDigit (tail s)
                       fPart = takeWhile (not.isDigit) s
                       sPart = dropWhile (not.isDigit) s

lettersToNumber::String->Integer
lettersToNumber []= 0
lettersToNumber s = toInteger (ord (head s)-ord 'A'+1) * 26^(length s-1)+ (lettersToNumber $ tail s)

numberToLetters::Integer->String
numberToLetters 0 = ""
numberToLetters n
  | mod n 26==0 = reverse$"Z" ++ (numberToLetters  (div n 26-1))
  | otherwise   = reverse$ [chr (fromIntegral (mod n 26 + fromIntegral( ord 'A')-1))] ++ (numberToLetters $ div n 26)

import Data.Char

main = interact $pars

pars s
 | and (map isDigit s) = []
 | head s == 'R' && isDigit (s!!1) = (numberToLetters (read (tail cPart)))
                                  ++ rPart
 | otherwise = "R"++sPart++ "C" ++  ( show (lettersToNumber fPart))
                where  rPart = (takeWhile isDigit (tail s))
                       cPart = dropWhile isDigit (tail s)
                       fPart = takeWhile (not.isDigit) s
                       sPart = dropWhile (not.isDigit) s

lettersToNumber::String->Int
lettersToNumber []= 0
lettersToNumber s = (ord (head s)-ord 'A'+1) * 26^(length s-1)+ (lettersToNumber $ tail s)

numberToLetters::Int->String
numberToLetters 0 = ""
numberToLetters n = reverse$ [chr (mod n 26 + ord 'A'-1)] ++ (numberToLetters $ div n 26)

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

import Data.Char

data CoordinateType = A | B deriving (Eq, Show)

main = do
	contents <- getLine
	let
		n = read $ head $ lines contents
	coordinates <- getLines n
	mapM_ putStrLn $ convertCoordinates coordinates
	return ()

getLines :: Int -> IO [String]
getLines 0 = return []
getLines n = do
	x <- getLine
	xs <- getLines (n-1)
	return (x:xs)

-- Type A if not letters are found after a number (ABXY)
-- Type B if letters are found after a number (RXCY)
-- Regular expressions could be used, but let's keep things simple
coordinateType :: String -> CoordinateType
coordinateType (x:xs) = coordinateType' x xs
	where
		coordinateType' :: Char -> String -> CoordinateType
		coordinateType' _ [] = A
		coordinateType' prev (x:xs)
			| isDigit prev && isLetter x = B
			| otherwise = coordinateType' x xs

letterToNum :: Char -> Int
letterToNum letter = ord letter - 64

numToLetter :: Int -> Char
numToLetter num = chr $ num + 64

letterColToNum :: String -> Int
letterColToNum [] = 0
letterColToNum (x:xs) = 26^length(xs)*(letterToNum x) + letterColToNum xs

numToLetterCol :: Int -> String
numToLetterCol num = reverse $ numToLetterCol' num
	where
		numToLetterCol' :: Int -> String
		numToLetterCol' num
			| num <= 26 = [numToLetter num]
			| otherwise = numToLetter (num `mod` 26) : numToLetterCol' (num `quot` 26)

translateCoordinate :: String -> String
translateCoordinate coord
	| coord_type == A =
		let
			col = takeWhile (isLetter) coord
			row = takeWhile (isDigit) $ dropWhile (isLetter) coord
		in
			"R" ++ row ++ "C" ++ (show $ letterColToNum col)
	| coord_type == B =
		let
			col = read $ tail $ dropWhile (isDigit) $ tail coord
			row = takeWhile (isDigit) $ tail coord
		in
			numToLetterCol col ++ row
	where
		coord_type = coordinateType coord

convertCoordinates :: [String] -> [String]
convertCoordinates [] = []
convertCoordinates (x:xs) = translateCoordinate x : convertCoordinates xs

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

import Data.Char

data CoordinateType = A | B deriving (Eq, Show)

main = do
	contents <- getLine
	let
		n = read $ head $ lines contents
	coordinates <- getLines n
	putStrLn $ show $ convertCoordinates coordinates
	return ()

getLines :: Int -> IO [String]
getLines 0 = return []
getLines n = do
	x <- getLine
	xs <- getLines (n-1)
	return (x:xs)

-- Type A if not letters are found after a number (ABXY)
-- Type B if letters are found after a number (RXCY)
-- Regular expressions could be used, but let's keep things simple
coordinateType :: String -> CoordinateType
coordinateType (x:xs) = coordinateType' x xs
	where
		coordinateType' :: Char -> String -> CoordinateType
		coordinateType' _ [] = A
		coordinateType' prev (x:xs)
			| isDigit prev && isLetter x = B
			| otherwise = coordinateType' x xs

letterToNum :: Char -> Int
letterToNum letter = ord letter - 64

numToLetter :: Int -> Char
numToLetter num = chr $ num + 64

letterColToNum :: String -> Int
letterColToNum [] = 0
letterColToNum (x:xs) = 26^length(xs)*(letterToNum x) + letterColToNum xs

numToLetterCol :: Int -> String
numToLetterCol num = reverse $ numToLetterCol' num
	where
		numToLetterCol' :: Int -> String
		numToLetterCol' num
			| num < 26 = [numToLetter num]
			| otherwise = numToLetter (num `mod` 26) : numToLetterCol' (num `quot` 26)

translateCoordinate :: String -> String
translateCoordinate coord
	| coord_type == A =
		let
			col = takeWhile (isLetter) coord
			row = takeWhile (isDigit) $ dropWhile (isLetter) coord
		in
			"R" ++ row ++ "C" ++ (show $ letterColToNum col)
	| coord_type == B =
		let
			col = read $ tail $ dropWhile (isDigit) $ tail coord
			row = takeWhile (isDigit) $ tail coord
		in
			numToLetterCol col ++ row
	where
		coord_type = coordinateType coord

convertCoordinates :: [String] -> [String]
convertCoordinates [] = []
convertCoordinates (x:xs) = translateCoordinate x : convertCoordinates xs

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

import Data.Char

data CoordinateType = A | B deriving (Eq, Show)

main = do
	contents <- getLine
	let
		n = read $ head $ lines contents
	coordinates <- getLines n
	mapM_ putStrLn $ convertCoordinates coordinates
	return ()

getLines :: Int -> IO [String]
getLines 0 = return []
getLines n = do
	x <- getLine
	xs <- getLines (n-1)
	return (x:xs)

-- Type A if not letters are found after a number (ABXY)
-- Type B if letters are found after a number (RXCY)
-- Regular expressions could be used, but let's keep things simple
coordinateType :: String -> CoordinateType
coordinateType (x:xs) = coordinateType' x xs
	where
		coordinateType' :: Char -> String -> CoordinateType
		coordinateType' _ [] = A
		coordinateType' prev (x:xs)
			| isDigit prev && isLetter x = B
			| otherwise = coordinateType' x xs

letterToNum :: Char -> Int
letterToNum letter = ord letter - 64

numToLetter :: Int -> Char
numToLetter num = chr $ num + 64

letterColToNum :: String -> Int
letterColToNum [] = 0
letterColToNum (x:xs) = 26^length(xs)*(letterToNum x) + letterColToNum xs

numToLetterCol :: Int -> String
numToLetterCol num = reverse $ numToLetterCol' num
	where
		numToLetterCol' :: Int -> String
		numToLetterCol' num
			| num < 26 = [numToLetter num]
			| otherwise = numToLetter (num `mod` 26) : numToLetterCol' (num `quot` 26)

translateCoordinate :: String -> String
translateCoordinate coord
	| coord_type == A =
		let
			col = takeWhile (isLetter) coord
			row = takeWhile (isDigit) $ dropWhile (isLetter) coord
		in
			"R" ++ row ++ "C" ++ (show $ letterColToNum col)
	| coord_type == B =
		let
			col = read $ tail $ dropWhile (isDigit) $ tail coord
			row = takeWhile (isDigit) $ tail coord
		in
			numToLetterCol col ++ row
	where
		coord_type = coordinateType coord

convertCoordinates :: [String] -> [String]
convertCoordinates [] = []
convertCoordinates (x:xs) = translateCoordinate x : convertCoordinates xs

import Data.Char
import Debug.Trace
import Control.Monad

data IdType = Excel | RC

getInput :: IO [String]
getInput = do
	linesnum <- (liftM read) getLine
	sequence $ replicate linesnum getLine

identifyType :: String -> IdType
identifyType s = if head s /= 'R'
	then Excel
	else if not . isDigit $ s !! 1
		then Excel
		else if any (not . isDigit) $ drop 2 s then RC else Excel

excelToRC :: String -> String
excelToRC s = "R" ++ row ++ "C" ++ convertedColumn
	where
		(column, row) = parseExcel s
		convertedColumn = (show . id) $ foldl decodeAlpha 0 column
		parseExcel = break isDigit
		decodeAlpha t c = (t * 26) + (ord c - ord 'A' + 1)

rCToExcel :: String -> String
rCToExcel s = convertedColumn ++ row
	where
		(row, column) = parseRc s
		parseRc s = let (a,b) = break (== 'C') (tail s) in (a, tail b)
		convertedColumn = decodeNumber (read column) ""
		decodeNumber 0 s = s
		decodeNumber x s = if x < 26
			then decodeDigit x : s
			else decodeNumber m newS
				where
					(d, m) = divMod x 26
					newS = decodeDigit m : s
		decodeDigit x = chr (ord 'A' + x - 1)

convert :: String -> String
convert s = case identifyType s of
	Excel -> excelToRC s
	RC -> rCToExcel s

main = do
	coords <- getInput
	mapM_ (putStrLn . convert) coords

import Data.Char
import Debug.Trace
import Control.Monad

data IdType = Excel | RC

getInput :: IO [String]
getInput = do
	linesnum <- (liftM read) getLine
	sequence $ replicate linesnum getLine

identifyType :: String -> IdType
identifyType s = if head s /= 'R'
	then Excel
	else if not . isDigit $ s !! 1
		then Excel
		else if any (not . isDigit) $ drop 2 s then RC else Excel

excelToRC :: String -> String
excelToRC s = "R" ++ row ++ "C" ++ convertedColumn
	where
		(column, row) = parseExcel s
		convertedColumn = (show . id) $ foldl decodeAlpha 0 column
		parseExcel = break isDigit
		decodeAlpha t c = (t * 26) + (ord c - ord 'A' + 1)

rCToExcel :: String -> String
rCToExcel s = convertedColumn ++ row
	where
		(row, column) = parseRc s
		parseRc s = let (a,b) = break (== 'C') (tail s) in (a, tail b)
		convertedColumn = decodeNumber (read column) ""
		decodeNumber 0 s = s
		decodeNumber x s = if x < 26
			then decodeDigit x : s
			else decodeNumber d newS
				where
					(d, m) = divMod x 26
					newS = decodeDigit m : s
		decodeDigit x = chr (ord 'A' + x - 1)

convert :: String -> String
convert s = case identifyType s of
	Excel -> excelToRC s
	RC -> rCToExcel s

main = do
	coords <- getInput
	mapM_ (putStrLn . convert) coords

import Data.Char
import Debug.Trace
import Control.Monad

data IdType = Excel | RC

getInput :: IO [String]
getInput = do
	linesnum <- (liftM read) getLine
	sequence $ replicate linesnum getLine

identifyType :: String -> IdType
identifyType s = if head s /= 'R'
	then Excel
	else if not . isDigit $ s !! 1
		then Excel
		else if any (not . isDigit) $ drop 2 s then RC else Excel

excelToRC :: String -> String
excelToRC s = "R" ++ row ++ "C" ++ convertedColumn
	where
		(column, row) = parseExcel s
		convertedColumn = (show . id) $ foldl decodeAlpha 0 column
		parseExcel = break isDigit
		decodeAlpha t c = (t * 26) + (ord c - ord 'A' + 1)

rCToExcel :: String -> String
rCToExcel s = convertedColumn ++ row
	where
		(row, column) = parseRc s
		parseRc s = let (a,b) = break (== 'C') (tail s) in (a, tail b)
		convertedColumn = decodeNumber (read column) ""
		decodeNumber 0 s = s
		decodeNumber x s = if x < 26
			then s ++ [decodeDigit x]
			else decodeNumber m newS
				where
					(d, m) = divMod x 26
					newS = s ++ [decodeDigit d]
		decodeDigit x = chr (ord 'A' + x - 1)

convert :: String -> String
convert s = case identifyType s of
	Excel -> excelToRC s
	RC -> rCToExcel s

main = do
	coords <- getInput
	mapM_ (putStrLn . convert) coords

{-# LANGUAGE ScopedTypeVariables #-}
module Main where

import Data.List
import Data.Char

letters = map (\x -> chr (ord 'A' + (x - 1) `mod` 26)) . reverse . takeWhile (>0) . iterate (\x -> (x-1) `div` 26)
numbers = sum . zipWith (*) (iterate (*26) 1) . reverse . map (\x -> ord x - ord 'A' + 1)

convert :: [String] -> String
convert ("R":r:"C":c:[]) = letters (read r) ++ c
convert (r:c:[]) = "R" ++ show (numbers r) ++ "C" ++ c

main = do
    (n :: Int,cells) <- getContents >>= return . (\(n:cells) -> (read n,map (map toUpper) cells)) . lines
    mapM (putStrLn . convert . groupBy (\l r -> isDigit l == isDigit r)) (take n cells)

import Data.List
import Data.Tree
import Data.Int
import Data.Maybe
import Data.Char
import Data.Functor
import Data.Function
import Data.Ord
import Data.Bits
import Data.Monoid
import Control.Monad
import Control.Monad.ST.Safe
import Control.Arrow
import qualified Data.Set as Set
import qualified Data.ByteString.Char8 as C
main= someFunc
rIn x= fst $ fromJust  $ C.readInt x
someFunc::IO()
someFunc = readLn >>= \n-> (solve=<<forM [1..n] (\i->C.getLine) )
solve xs = forM_ xs $ \i->  C.putStrLn $ slv1 i
slv1 xs = slv2 $ second  (C.break (isLetter)) $ C.break (isDigit) xs
slv2 (a,(b,c))= if c/=C.empty then C.append (slv5 $ rIn $ C.tail c) b else  C.append (C.cons 'R' b) (C.cons 'C' $ slv3 a)
se_t2 = Set.fromList (['A'..'Z'])
slv3::C.ByteString->C.ByteString
slv3 xs =C.pack $ show $ fst $ C.foldr (\a (b1,b2)->((Set.findIndex a se_t2+1)* 26^b2 +b1, b2+1)) (0,0) xs
slv4 0 = []
slv4 x=let md = x `mod` 26; dv= x `div` 26 in slv4 (if md==0 then dv-1 else dv) ++[if md==0 then 26 else md]
slv5 x =C.pack $ map (flip Set.elemAt se_t2.(+(-1))) $ slv4 x

import Data.Char
import Text.ParserCombinators.ReadP

fromChar :: Char -> Int
fromChar c = (ord c - ord 'A' + 1)

toChar :: Int -> Char
toChar n
  | n < 0 || n > 26  =  error "toChar: argument not in [1..26]"
  | otherwise        =  chr (ord 'A' + n - 1)

fromABC :: String -> Int
fromABC "" = 0
fromABC s = sum (zipWith (*) (map fromChar s) (_26 (length s)))
  where
    _26 0 = []
    _26 n = (26^(n-1)):(_26 (n-1))

toABC :: Int -> String
toABC 0  =  ""
toABC n
  | n <= 26    =  [toChar n]
  | a == 0     =  (toABC (div n 26 - 1)) ++ "Z"
  | otherwise  =  (toABC (div n 26)) ++ [toChar a]
  where
    a = mod n 26

parserRC :: ReadP (Int, Int)
parserRC = do
    string "R"
    col <- many1 $ satisfy isDigit
    string "C"
    row <- many1 $ satisfy isDigit
    return (read col, read row)

parserA1 :: ReadP (Int, Int)
parserA1 = do
    col <- many1 $ satisfy isAlpha
    row <- many1 $ satisfy isDigit
    return (fromABC col, read row)

getCell :: ReadP (Int, Int) -> String -> Maybe (Int, Int)
getCell parser s
  | 0 < length xs  =  Just (fst (head xs))
  | otherwise  =  Nothing
  where
    xs  =  filter (\x -> snd x == "") (readP_to_S parser s)

checkString :: ReadP (Int, Int) -> String -> Bool
checkString parser s  =  getCell parser s /= Nothing

checkRC :: String -> Bool
checkRC  =  checkString parserRC

checkA1 :: String -> Bool
checkA1  =  checkString parserA1

toRC :: (Int, Int) -> String
toRC (n, m)  =  concat ["R", show n, "C", show m]

toA1 :: (Int, Int) -> String
toA1 (n, m)  =  concat [toABC n, show m]

solve :: String -> String
solve s
  | checkRC s  =  toA1 (r, c)
  | checkA1 s  =  toRC (n, m)
  | otherwise  =  "NO"
  where
    (Just (r, c))  =  getCell parserRC s
    (Just (n, m))  =  getCell parserA1 s

main :: IO ()
main = do
    n <- readLn
    lines <- sequence (replicate n getLine)
    sequence_ (map (putStrLn . solve) lines)

import Data.Char
import Text.ParserCombinators.ReadP

fromChar :: Char -> Int
fromChar c = (ord c - ord 'A' + 1)

toChar :: Int -> Char
toChar n
  | n < 0 || n > 26  =  error "toChar: argument not in [1..26]"
  | otherwise        =  chr (ord 'A' + n - 1)

fromABC :: String -> Int
fromABC "" = 0
fromABC s = sum (zipWith (*) (map fromChar s) (_26 (length s)))
  where
    _26 0 = []
    _26 n = (26^(n-1)):(_26 (n-1))

toABC :: Int -> String
toABC 0  =  ""
toABC n
  | n <= 26    =  [toChar n]
  | a == 0     =  (toABC (div n 26 - 1)) ++ "Z"
  | otherwise  =  (toABC (div n 26)) ++ [toChar a]
  where
    a = mod n 26

parserRC :: ReadP (Int, Int)
parserRC = do
    string "R"
    row <- many1 $ satisfy isDigit
    string "C"
    col <- many1 $ satisfy isDigit
    return (read col, read row)

parserA1 :: ReadP (Int, Int)
parserA1 = do
    col <- many1 $ satisfy isAlpha
    row <- many1 $ satisfy isDigit
    return (fromABC col, read row)

getCell :: ReadP (Int, Int) -> String -> Maybe (Int, Int)
getCell parser s
  | 0 < length xs  =  Just (fst (head xs))
  | otherwise  =  Nothing
  where
    xs  =  filter (\x -> snd x == "") (readP_to_S parser s)

checkString :: ReadP (Int, Int) -> String -> Bool
checkString parser s  =  getCell parser s /= Nothing

checkRC :: String -> Bool
checkRC  =  checkString parserRC

checkA1 :: String -> Bool
checkA1  =  checkString parserA1

toRC :: (Int, Int) -> String
toRC (n, m)  =  concat ["R", show n, "C", show m]

toA1 :: (Int, Int) -> String
toA1 (n, m)  =  concat [toABC n, show m]

solve :: String -> String
solve s
  | checkRC s  =  toA1 (r, c)
  | checkA1 s  =  toRC (n, m)
  | otherwise  =  "NO"
  where
    (Just (r, c))  =  getCell parserRC s
    (Just (n, m))  =  getCell parserA1 s

main :: IO ()
main = do
    n <- readLn
    lines <- sequence (replicate n getLine)
    sequence_ (map (putStrLn . solve) lines)

import Control.Monad

readAlphas (x : xs) | 'A' <= x && x <= 'Z' =
  x : readAlphas xs
readAlphas _ = ""

readDigits (x : xs) | '0' <= x && x <= '9' =
  x : readDigits xs
readDigits _ = ""

crToXY c r = 'R' : show r ++ 'C' : (show . convert . reverse) c
  where
    convert [] = 0
    convert (x : xs) = let v = fromEnum x - 64 in
      v + convert xs * 26

xyToCR x y = convert y ++ show x
  where
    convert 0 = ""
    convert n = convert (div n 26) ++ [char]
      where
        char | n `mod` 26 == 0 = 'Z'
             | otherwise = toEnum (n `mod` 26 + 64) :: Char

main = do
  line <- getLine
  let n = read line :: Int
  forM_ [1..n] $ \i -> do
    line <- getLine
    let a = readAlphas line
    let line' = drop (length a) line
    let b = readDigits line'
    let line'' = drop (length b) line'
    case line'' of
      "" -> do let c = a
               let r = read b :: Int
               putStrLn $ crToXY c r
      _  -> do let x = read b :: Int
               let y = read (drop 1 line'') :: Int
               putStrLn $ xyToCR x y

import Data.Char
import Data.List

calcAlpha :: String -> Int -> Int
calcAlpha (x:[]) num = num * ((ord x) - (ord 'A') + 1)
calcAlpha (x:xs) num = num * ((ord x) - (ord 'A') + 1) + (calcAlpha xs (num*26))

alphaToRC alpha num = "R" ++ num ++ "C" ++ show (calcAlpha (reverse alpha) 1)

calcRC n
 |n == 0 = []
 |otherwise = calcRC (n `div` 26) ++ [chr ((ord 'A') - 1 + (n `mod` 26))]

rcToAlpha :: String -> String -> String
rcToAlpha r c = calcRC (read c :: Int) ++ r

parseInp :: String -> String -> [String]
parseInp [] y = [y]
parseInp (x:xs) y
 |y  == []   = parseInp xs [x]
 |isDigit (x) == isDigit (head y) = parseInp xs (y++[x])
 |otherwise =  [y] ++ parseInp xs [x]

solveTC :: Integer -> IO ()
solveTC n = do
             if (n == 0)
              then return ()
              else do
                     line <- getLine
                     let inp = parseInp line ""
                     if length inp == 2
                        then putStrLn $ alphaToRC (inp !! 0) (inp !! 1)
                        else putStrLn $ rcToAlpha (inp !! 1) (inp !! 3)

                     solveTC (n-1)

main = do
        line <- getLine
        let tc = (read line :: Integer)
        solveTC tc

printAns :: Integer -> Integer -> IO()
printAns tc s = putStrLn $ ("Case #" ++ (show tc) ++ ": " ++ (show s))

makeData :: [Char] -> [Integer] -> [Integer]
makeData ('C':[]) (y:_)   = [y `div` 2]
makeData (x:[])   (y:_)   = [y]
makeData ('C':xs) (y:ys)  = (y `div` 2) : makeData xs ys
makeData (x:xs)    (y:ys) = y   : makeData xs ys

listCnt c xs = sum $ map (\x -> if x == c then 1 else 0) xs

cntEach (c:[]) xs = [listCnt c xs]
cntEach (c:cs) xs = listCnt c xs : cntEach cs xs

solveEach :: String -> Integer
solveEach line = foldr (min) 1000 (makeData "HACKERCUP" (cntEach "HACKERCUP" line))

solveTC :: Integer -> Integer ->  IO ()
solveTC 0 _ = return ()
solveTC te tc= do
                line <- getLine
                printAns tc (solveEach line)
                solveTC (te-1) (tc+1)

main :: IO ()
main = do
         line <- getLine
         let tc = (read line :: Integer)
         solveTC tc 1

import Data.Char (ord, chr)

main :: IO ()
main = do
  s <- getContents
  putStr (unlines $ map process (tail $ lines s))

lettersBase = ord 'Z' - ord 'A' + 1

process :: String -> String
process s | (length parsed) == 2 = coordsToRC $ coordsFromAB parsed
          | otherwise            = coordsToAB $ coordsFromRC parsed
    where parsed = chainParse [isLetter, isDigit, isLetter, isDigit] s

coordsFromAB :: [String] -> (Int, Int)
coordsFromAB [col, row] = (read row, lettersToInt col)

coordsFromRC :: [String] -> (Int, Int)
coordsFromRC ["R", row, "C", col] = (read row, read col)

lettersToInt :: String -> Int
lettersToInt s = sum $ map (\(val, k) -> val*k) (zip (reverse $ map (\c -> ord c - ord 'A' + 1) s) factors)
    where factors = iterate (*lettersBase) 1

intToLetters :: Int -> String
intToLetters 0 = []
intToLetters n = ( intToLetters (n `div` lettersBase) ) ++ [chr (m + ord 'A' - 1)]
    where m = n `mod` lettersBase

coordsToRC :: (Int, Int) -> String
coordsToRC (row, col) = "R" ++ (show row) ++ "C" ++ (show col)

coordsToAB :: (Int, Int) -> String
coordsToAB (row, col) = intToLetters col ++ show row

chainParse :: [( Char -> Bool )] -> String -> [String]
chainParse [] _ = []
chainParse _ "" = []
chainParse (f:fs) s = (extractChars f s):(chainParse fs (eatChars f s))

eatChars :: ( Char -> Bool ) -> String -> String
eatChars _ [] = []
eatChars f (c:cs) | f c       = eatChars f cs
                  | otherwise = (c:cs)

extractChars :: ( Char -> Bool ) -> String -> String
extractChars _ [] = []
extractChars f (c:cs) | f c       = c:(extractChars f cs)
                      | otherwise = ""

isDigit :: Char -> Bool
isDigit c = c>='0' && c<='9'

isLetter :: Char -> Bool
isLetter c = (c>='a' && c<='z') || (c>='A' && c<='Z')

import Control.Monad
import Data.Char
import Data.List
import Control.Applicative

main = do
  n <- readLn
  replicateM_ n (getLine >>= putStrLn . solve)

solve :: String -> String
solve str =
  let (a,(b,c)) = span isDigit <$> span isUpper str
  in if null c
       then encode1 (read b) (decodeCol a)
       else encode2 (read b) (read (snd (span isUpper c)))
  where
    encode1 :: Int -> Int -> String
    encode1 row col = "R" ++ show row ++ "C" ++ show col

    encode2 :: Int -> Int -> String
    encode2 row col = encodeCol col ++ show row

    decodeCol :: String -> Int
    decodeCol = foldl (\a c -> 26*a + ord c - ord 'A' + 1) 0

    encodeCol :: Int -> String
    encodeCol = reverse . unfoldr (\i -> if i == 0 then Nothing else Just (chr (i `mod` 26 + ord 'A' - 1), i `div` 26))

import Control.Monad
import Data.Char
import Data.List

main = do
  n <- readLn
  replicateM_ n (getLine >>= putStrLn . solve)

solve :: String -> String
solve str =
  let (a,b) = span isAlpha str
      (c,d) = span isDigit b
  in if null d then encode1 (read c) (decodeCol a) else encode2 (read c) (read (tail d))
  where
    encode1 :: Int -> Int -> String
    encode1 row col = "R" ++ show row ++ "C" ++ show col

    encode2 :: Int -> Int -> String
    encode2 row col = encodeCol col ++ show row

    decodeCol :: String -> Int
    decodeCol = foldl (\a c -> 26*a + ord c - ord 'A' + 1) 0

    encodeCol :: Int -> String
    encodeCol = reverse . unfoldr (\i -> if i == 0 then Nothing else Just (chr (i `mod` 26 + ord 'A' - 1), i `div` 26))

import Control.Monad
import Data.Char

parseRowColFormat :: String -> Maybe (Int, Int)
parseRowColFormat s@(x : _) = if x == 'R' then go "" "" s else Nothing where
    go "" "" [] = Nothing
    go (r:rs) "" [] = Nothing
    go rows@(r:rs) "" (_: xs) = go rows xs []
    go rows@(r:rs) cols@(c:cs) [] = Just (read rows, read cols)
    go "" "" (_ : xs) = go (takeWhile isDigit xs) "" (dropWhile isDigit xs)

parseStandartFormat :: String -> Maybe (String, Int)
parseStandartFormat s = go "" "" s where
    go "" "" [] = Nothing
    go (c:cs) "" [] = Nothing
    go cols@(c:cs) "" xss@(x:xs) = if any isAlpha xss then Nothing else go cols xss []
    go cols@(c:cs) rows@(r:rs) [] = Just (cols, read rows)
    go "" "" xs = go (takeWhile isAlpha xs) "" (dropWhile isAlpha xs)

col2Alpha :: Int -> String
col2Alpha = reverse . go where
    go 0 = ""
    go col = chr((col - 1) `mod` 26 + ord('A')) : col2Alpha ((col - 1) `div` 26)

alpha2Col :: String -> Int
alpha2Col col = foldl (\acc c -> acc*26 + ord(c) - ord('A') + 1) 0 col

parse :: String -> String
parse format = case parseRowColFormat format of
    Just (row, col) -> col2Alpha col ++ show row
    Nothing -> case parseStandartFormat format of
        Just (scol, srow) -> ('R' : show srow) ++ ('C' : (show $ alpha2Col scol))
        Nothing -> ""

main =
    read <$> getLine >>= \n ->
    replicateM_ n (parse <$> getLine >>= putStrLn)

module Main where

import Control.Arrow
import Data.Char
import Data.List
import Numeric
import Data.Function

isRXCY = dropWhile isAsciiUpper >>> dropWhile isDigit >>> null >>> not
toRXCY = readInt 26 isAsciiUpper (\x -> ord x - ord 'A' +1) >>> head >>> \ (c,r) -> 'R': r ++ "C" ++ show c
fromRXCY = groupBy ((==) `on` generalCategory) >>> (\ (_:r:_:c:_) -> (read c,r)) >>> uncurry (showIntAtBase 26 (\x -> chr $ x - 1 + ord 'A'))

main = do
  n:xs <- lines `fmap` getContents
  putStr $ ($ xs) $ take (read n) >>> map (\x -> if isRXCY x then fromRXCY x else toRXCY x) >>> unlines

import Data.Char
import Data.List

main :: IO ()
main = interact $ foldr ((++) . (++"\n")) "" . map show . map (read :: String -> Cell) . tail . lines

data Cell = Ax String Integer
          | Rxcy Integer Integer

instance Show Cell where
  show (Ax a x) = a ++ show x
  show (Rxcy x y) = "R" ++ show x ++ "C" ++ show y

instance Read Cell where
  readsPrec _ s = [(cvt xxs, "")]
    where xxs = foldl (\xs c -> if null xs then [[c]] else (if isAlpha (head (head xs)) == isAlpha c then (head xs++[c]):(tail xs) else [c]:xs)) [] s
          cvt [y, "C", x, "R"] = Rxcy (read x) (read y)
          cvt [x, a] = Ax a (read x)
          cvt _ = error "Input error"

convert :: Cell -> Cell
convert (Ax a x) = Rxcy x idx
  where nums = map (\c -> fromIntegral $ ord c - ord 'A' + 1) (reverse a)
        idx = sum $ map (\(b, y) -> b * 26 ^ y) $ zip nums [0..]
convert (Rxcy x y) = Ax str x
  where str = reverse $ unfoldr (\n -> if n == 0 then Nothing else let (d, m) = divMod (n - 1) 26 in Just (['A'..'Z'] !! (fromIntegral m), d)) y

module Main where

import Data.Char

readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
    [(x, "")] -> Just x
    _         -> Nothing

toString :: Int -> String
toString n = toStringAux n [] where
	toStringAux n ss = let (d, m) = divMod (n - 1) 26 in
		case d of
		0 -> chr (ord 'A' + m) : ss
		_ -> toStringAux d (chr (ord 'A' + m) : ss)

toInt :: String -> Int
toInt ss = toIntAux ss 0 where
	toIntAux (s : []) n = n + (ord s - ord 'A' + 1)
	toIntAux (s : ss) n = toIntAux ss (26 * (ord s - ord 'A' + 1) + n)

readRC :: String -> Maybe (Int, Int)
readRC s =
	let (r, s') = break isDigit s;
		(rs, s'') = break isAlpha s';
		(c, cs) = break isDigit s'' in do
	rn <- readMaybe rs
	cn <- readMaybe cs
	return (rn, cn)

readCR :: String -> Maybe (String, Int)
readCR s =
	let (cs, rs) = break isDigit s in
	do
	rn <- readMaybe rs
	return (cs, rn)

process :: String -> String
process s = case readRC s of
	Just (r, c) -> toString c ++ show r
	_ -> case readCR s of
		Just (c', r') -> "R" ++ show r' ++ "C" ++ show (toInt c')
		_ -> ""

main :: IO ()
main = do
	input <- getContents
	putStrLn (unlines (map process (tail (lines input))))

module Main(main) where

import Data.List(tails,foldl')
import Data.Maybe(fromJust)
import Control.Applicative

readInt :: String -> Int
readInt = read

alphaToInt :: Char -> Int
alphaToInt c = fromJust . lookup c $ zip ['A'..] [1..26]

strToInt :: String -> Int
strToInt s = let l = length s in strToInt' s l 0
  where strToInt' [] _ r   = r
        strToInt' _ 0 r = r
        strToInt' (s:ss) l r = strToInt' ss (l-1) (r+(alphaToInt s)*26^(l-1))

intToAlpha :: Int -> Char
intToAlpha i = fromJust . lookup i $ zip [1..26] ['A'..]

intToStr :: Int -> String
intToStr 0 = ""
intToStr i = reverse $ (intToAlpha ((i-1) `mod` 26 + 1)) : intToStr ((i-1)`div`26)

isCharNum :: Char -> Bool
isCharNum c = any (c==) "0123456789"

isExcel :: String -> Bool
isExcel = not . any isChange . tails
  where isChange (x:y:_) = (isCharNum x) && (not $ isCharNum y)
        isChange [x] = False
        isChange [] = False

fromExcel :: String -> (Int,Int)
fromExcel = f . break isCharNum
  where f (c,r) = (strToInt c, readInt r)

toExcel :: (Int,Int) -> String
toExcel (c,r) = (intToStr c) ++ (show r)

fromOther :: String -> (Int,Int)
fromOther s = let ((_:r),(_:c)) = break (=='C') s in (readInt c, readInt r)

toOther :: (Int,Int) -> String
toOther (c,r) = "R" ++ show r ++ "C" ++ show c

calc :: String -> String
calc str =if isExcel str
            then toOther $ fromExcel str
            else toExcel $ fromOther str

main = do
  n <- readInt <$> getLine
  sequence_ $ take n $ repeat ((putStrLn . calc) =<< getLine)

import Data.Char
import Data.List

main = interact $ unlines . map convert . tail . lines
convert s = case parseAlternate s of
              Just a -> showTrad a
              Nothing -> showAlternate (parseTrad s)

parseAlternate :: String -> Maybe (Int,Int)
parseAlternate ('R' : s) = case reads s of
                             [(r, 'C' : cs)] -> Just (r,read cs)
                             _ -> Nothing
parseAlternate _ = Nothing
showAlternate (r,c) = 'R' : show r ++ 'C' : show c

parseTrad :: String -> (Int,Int)
parseTrad s = (read r,decode c)
    where (c,r) = break isDigit s
showTrad (r,c) = encode c ++ show r

encode = reverse . map (chr . (ord 'A' - 1 +)) . unfoldr f
    where f 0 = Nothing
          f n = Just (r,q) where (q,r) = n `divMod` 26
decode = foldl1' f . map ((subtract $ ord 'A' - 1) . ord)
    where f a b = 26*a + b

import Data.Char
import Data.List

main = interact $ unlines . map convert . tail . lines
convert s = case parseAlternate s of
              Just a -> showTrad a
              Nothing -> showAlternate (parseTrad s)

parseAlternate :: String -> Maybe (Int,Int)
parseAlternate ('R' : s) = case reads s of
                             [(r, 'C' : cs)] -> Just (r,read cs)
                             _ -> Nothing
parseAlternate _ = Nothing
showAlternate (r,c) = 'R' : show r ++ 'C' : show c

parseTrad :: String -> (Int,Int)
parseTrad s = (read r,decode c)
    where (c,r) = break isDigit s
showTrad (r,c) = encode c ++ show r

encode = reverse . map (chr . (ord 'A' +)) . unfoldr f . pred
    where f 0 = Nothing
          f n = Just (r,q) where (q,r) = n `divMod` 26
decode = foldl1' f . map ((subtract $ ord 'A' - 1) . ord)
    where f a b = 26*a + b

import Data.Char
import Control.Monad

readRXCY :: String -> Maybe (Int, Int)
readRXCY ('R':s) = case span isNumber s of
    (x@(_:_), 'C':y@(_:_)) -> Just (read x, read y)
    _ -> Nothing
readRXCY _ = Nothing

toAB :: Int -> String
toAB n | 0 <= n && n < 26 = [chr $ 0x41 + n]
       | otherwise = toAB (n `div` 26) ++ toAB (n `mod` 26)

readAB :: String -> (Int, Int)
readAB s = readAB' 0 s
  where
    readAB' x (c:cs)
        | isNumber c = (read $ c:cs, x)
        | otherwise = readAB' (x * 26 + ord c - 0x40) cs

main = do
    n <- fmap read getLine
    forM_ [1..n] $ \_ -> do
        line <- getLine
        case readRXCY line of
            Just (x, y) -> putStrLn $ toAB (y - 1) ++ show x
            Nothing -> let (x, y) = readAB line
                       in putStrLn $ "R" ++ show x ++ "C" ++ show y

import Data.Char
import Control.Monad

readRXCY :: String -> Maybe (Int, Int)
readRXCY ('R':s) = case span isNumber s of
    (x@(_:_), 'C':y@(_:_)) -> Just (read x, read y)
    _ -> Nothing
readRXCY _ = Nothing

toAB :: Int -> String
toAB n | n == 0 = ""
       | 0 < n && n <= 26 = [chr $ 0x40 + n]
       | otherwise = toAB (n `div` 26) ++ toAB (n `mod` 26)

readAB :: String -> (Int, Int)
readAB s = readAB' 0 s
  where
    readAB' x (c:cs)
        | isNumber c = (read $ c:cs, x)
        | otherwise = readAB' (x * 26 + ord c - 0x40) cs

main = do
    n <- fmap read getLine
    forM_ [1..n] $ \_ -> do
        line <- getLine
        case readRXCY line of
            Just (x, y) -> putStrLn $ toAB y ++ show x
            Nothing -> let (x, y) = readAB line
                       in putStrLn $ "R" ++ show x ++ "C" ++ show y

import Data.Char
import Control.Monad

readRXCY :: String -> Maybe (Int, Int)
readRXCY ('R':s) = case span isNumber s of
    (x@(_:_), 'C':y@(_:_)) -> Just (read x, read y)
    _ -> Nothing
readRXCY _ = Nothing

toAB :: Int -> String
toAB n | n == 0 = ""
       | 0 < n && n <= 26 = [chr $ 0x40 + n]
       | otherwise = toAB (n `div` 26)
            ++ toAB (if n `mod` 26 == 0 then 26 else n `mod` 26)

readAB :: String -> (Int, Int)
readAB s = readAB' 0 s
  where
    readAB' x (c:cs)
        | isNumber c = (read $ c:cs, x)
        | otherwise = readAB' (x * 26 + ord c - 0x40) cs

main = do
    n <- fmap read getLine
    forM_ [1..n] $ \_ -> do
        line <- getLine
        case readRXCY line of
            Just (x, y) -> putStrLn $ toAB y ++ show x
            Nothing -> let (x, y) = readAB line
                       in putStrLn $ "R" ++ show x ++ "C" ++ show y

import Data.Char
import Data.List

toAlp s 0 = s
toAlp s x = let x1 = x-1 in
    toAlp ((chr ((mod x1 26) + 65)):s) (div x1 26)

toNum x [] = x
toNum x (s:ss) = toNum (26*x + (ord s - 64)) ss

proc s = case groupBy (\x y -> isDigit x == isDigit y) s of
    [_,r,_,c] -> (toAlp [] $ read r) ++ c
    [r,c] -> "R" ++ (show (toNum 0 $ reverse r)) ++ "C" ++ c

main = interact $ unlines.map proc.tail.lines

import Data.Char
import Data.List

toAlp s 0 = s
toAlp s x = let x1 = x-1 in
    toAlp ((chr ((mod x1 26) + 65)):s) (div x1 26)

toNum x [] = x
toNum x (s:ss) = toNum (26*x + (ord s - 64)) ss

proc s = case groupBy (\x y -> isDigit x == isDigit y) s of
    [_,r,_,c] -> (toAlp [] $ read c) ++ r
    [c,r] -> "R" ++ (show (toNum 0 $ reverse r)) ++ "C" ++ c

main = interact $ unlines.map proc.tail.lines

import Data.Char
import Data.List
import Control.Applicative

main = do
  n <- read <$> getLine
  css <- mapM (\i -> solve n <$> getLine) [1..n]
  putStrLn $ unlines css

solve :: Int -> String -> String
solve _ cs = if isRXCY cs then fromRXCY cs
                          else toRXCY cs

isRXCY :: String -> Bool
isRXCY = not.all isDigit.dropWhile isAlpha

toRXCY :: String -> String
toRXCY cs' = "R" ++ ns ++ "C" ++ rs
   where (cs,ns) = span isAlpha cs'
         rs = show $ sum $ zipWith (*) (map (26^) [0..]) $ reverse $ map (\c->(ord c)-64) cs

fromRXCY :: String -> String
fromRXCY (c:cs) = ys' ++ xs
   where (xs,(y':ys)) = span isDigit cs
         n = sum $ zipWith (*) (map (10^) [0..]) $ reverse $ map (read.return) ys
         ys' = map (chr.(64+)) $ reverse $ to26 n

to26 :: Int -> [Int]
to26 n = if q == 0 then [r] else r:(to26 q)
   where (q,r) = divMod n 26

module Main where
import Control.Monad
import Data.Char

countSeg :: String -> Integer
countSeg [] = 0
countSeg (a:[]) = 1
countSeg (a:b:c)
  |isAlpha a==isAlpha b =   countSeg(b:c)
  |otherwise            = 1+countSeg(b:c)

alphaToInt :: String -> Int
alphaToInt (a:[]) = ord a - 64
alphaToInt (a:b) = ((ord a)-64)*26+alphaToInt b

intToAlpha :: Int -> String
intToAlpha n
  | n<26      = chr (65+n) : []
  | otherwise = (intToAlpha (div n 26 - 1)) ++ ((chr (65+(mod n 26))):[])

splitAll :: String -> [String]
splitAll [] = []
splitAll s = do
  let (p:q) = s
  if isAlpha p then
    let (a,b) = splitAt (length $takeWhile isAlpha s) s in
    a:splitAll b
  else
    let (a,b) = splitAt (length $takeWhile (not.isAlpha) s) s in
    a:splitAll b

solve :: Integer -> IO ()
solve n = do
    if (n==0) then return ()
    else do
        line <- getLine
        if countSeg line == 2 then
            let (a:b:_)=splitAll line in
            putStr $"R"++b++"C"++(show $alphaToInt a)++"\n"
        else
            let (a:b:c:d:_)=splitAll line in
            putStr $intToAlpha (((read::String->Int) d)-1)++b++"\n"
        solve (n-1)

main = do
  buf <- getLine
  let (n:_) = map (read::String->Integer) (buf:[])
  solve n

import Control.Monad
import Data.Char

readInt :: IO Integer
readInt = readLn

countSeg :: String -> Integer
countSeg [] = 0
countSeg (a:[]) = 1
countSeg (a:b:c)
  |isAlpha a==isAlpha b =   countSeg(b:c)
  |otherwise            = 1+countSeg(b:c)

alphaToInt :: String -> Int
alphaToInt (a:[]) = ord a - 64
alphaToInt (a:b) = ((ord a)-64)*26+alphaToInt b

intToAlpha :: Int -> String
intToAlpha n
  | n<26      = chr (65+n) : []
  | otherwise = (intToAlpha (div n 26 - 1)) ++ ((chr (65+(mod n 26))):[])

splitAll :: String -> [String]
splitAll [] = []
splitAll s = do
  let (p:q) = s
  if isAlpha p then
    let (a,b) = splitAt (length $takeWhile isAlpha s) s in
    a:splitAll b
  else
    let (a,b) = splitAt (length $takeWhile (not.isAlpha) s) s in
    a:splitAll b

solve :: Integer -> IO ()
solve n = do
    if (n==0) then return ()
    else do
        line <- getLine
        if countSeg line == 2 then
            let (a:b:_)=splitAll line in
            print $"R"++(show $alphaToInt a)++"C"++b
        else
            let (a:b:c:d:_)=splitAll line in
            print $intToAlpha (((read::String->Int) b)-1)++d
        solve (n-1)

main = do
  n <- readInt
  solve n

module Main where
import Control.Monad
import Data.Char

countSeg :: String -> Integer
countSeg [] = 0
countSeg (a:[]) = 1
countSeg (a:b:c)
  |isAlpha a==isAlpha b =   countSeg(b:c)
  |otherwise            = 1+countSeg(b:c)

alphaToInt :: String -> Int
alphaToInt (a:[]) = ord a - 64
alphaToInt (a:b) = ((ord a)-64)*26+alphaToInt b

intToAlpha :: Int -> String
intToAlpha n
  | n<26      = chr (65+n) : []
  | otherwise = (intToAlpha (div n 26 - 1)) ++ ((chr (65+(mod n 26))):[])

splitAll :: String -> [String]
splitAll [] = []
splitAll s = do
  let (p:q) = s
  if isAlpha p then
    let (a,b) = splitAt (length $takeWhile isAlpha s) s in
    a:splitAll b
  else
    let (a,b) = splitAt (length $takeWhile (not.isAlpha) s) s in
    a:splitAll b

solve :: Integer -> IO ()
solve n = do
    if (n==0) then return ()
    else do
        line <- getLine
        if countSeg line == 2 then
            let (a:b:_)=splitAll line in
            print $"R"++b++"C"++(show $alphaToInt a)
        else
            let (a:b:c:d:_)=splitAll line in
            print $intToAlpha (((read::String->Int) d)-1)++b
        solve (n-1)

main = do
  buf <- getLine
  let (n:_) = map (read::String->Integer) (buf:[])
  solve n

module Main where
import Control.Monad
import Data.Char

countSeg :: String -> Integer
countSeg [] = 0
countSeg (a:[]) = 1
countSeg (a:b:c)
  |isAlpha a==isAlpha b =   countSeg(b:c)
  |otherwise            = 1+countSeg(b:c)

alphaToInt :: String -> Int
alphaToInt (a:[]) = ord a - 64
alphaToInt (a:b) = ((ord a)-64)*26+alphaToInt b

intToAlpha :: Int -> String
intToAlpha n
  | n<26      = chr (65+n) : []
  | otherwise = (intToAlpha (div n 26 - 1)) ++ ((chr (65+(mod n 26))):[])

splitAll :: String -> [String]
splitAll [] = []
splitAll s = do
  let (p:q) = s
  if isAlpha p then
    let (a,b) = splitAt (length $takeWhile isAlpha s) s in
    a:splitAll b
  else
    let (a,b) = splitAt (length $takeWhile (not.isAlpha) s) s in
    a:splitAll b

solve :: Integer -> IO ()
solve n = do
    if (n==0) then return ()
    else do
        line <- getLine
        if countSeg line == 2 then
            let (a:b:_)=splitAll line in
            putStr $"R"++b++"C"++(show $alphaToInt a)
        else
            let (a:b:c:d:_)=splitAll line in
            putStr $intToAlpha (((read::String->Int) d)-1)++b
        solve (n-1)

main = do
  buf <- getLine
  let (n:_) = map (read::String->Integer) (buf:[])
  solve n

module Main where

import Data.Char
import Control.Monad

data Cell = Cell {
  row :: Int,
  column :: Int
} deriving (Show)

showRC :: Cell -> String
showRC c = "R" <> show (row c) <> "C" <> show (column c)

showCR :: Cell -> String
showCR c = abbr (column c) <> show (row c)

radix = 26

abbr :: Int -> String
abbr x = abbr0 x ""
  where
    abbr0 0 acc = acc
    abbr0 x acc = let y = ord 'A' + (x `mod` radix) - 1 in abbr0 (x `div` radix) (chr y:acc)

fromAbbr :: String -> Int
fromAbbr x = fromAbbr0 x 0
  where
    fromAbbr0 [] acc = acc
    fromAbbr0 (a:xs) acc = fromAbbr0 xs $ acc * radix + (ord a - ord 'A' + 1)

data Parsed = ParsedRC Cell
            | ParsedCR Cell
            | Unknown String
  deriving (Show)

headBy :: (a -> Bool) -> [a] -> ([a], [a])
headBy pred line = let match = takeWhile pred line in splitAt (length match) line

split :: String -> [String]
split line = reverse $ split1 line []
  where
    split1 [] acc = acc
    split1 line acc = let (chars, rest) = headBy (not . isDigit) line in
      split2 rest $ chars:acc
    split2 [] acc = acc
    split2 line acc = let (digits, rest) = headBy isDigit line in
      split1 rest $ digits:acc

parseCell :: String -> Parsed
parseCell line = case split line of
  ["R", r, "C", c] -> ParsedRC Cell { row = read r, column = read c }
  [c, r]  -> ParsedCR Cell { row = read r, column = fromAbbr c }
  _ -> Unknown line

convert :: Parsed -> String
convert (Unknown x) = x
convert (ParsedCR c) = showRC c
convert (ParsedRC c) = showCR c

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  inputs <- replicateM n getLine
  forM_ inputs $ print . convert . parseCell

module Main where

import Data.Char
import Control.Monad

data Cell = Cell {
  row :: Int,
  column :: Int
} deriving (Show)

showRC :: Cell -> String
showRC c = "R" <> show (row c) <> "C" <> show (column c)

showCR :: Cell -> String
showCR c = abbr (column c) <> show (row c)

radix = 26

abbr :: Int -> String
abbr x = abbr0 (x - 1) ""
  where
    abbr0 0 ""  = "A"
    abbr0 0 acc = acc
    abbr0 x acc = let y = ord 'A' + (x `mod` radix) in abbr0 (x `div` radix) (chr y:acc)

fromAbbr :: String -> Int
fromAbbr x = 1 + fromAbbr0 x 0
  where
    fromAbbr0 [] acc = acc
    fromAbbr0 (a:xs) acc = fromAbbr0 xs $ acc * radix + (ord a - ord 'A')

data Parsed = ParsedRC Cell
            | ParsedCR Cell
            | Unknown String
  deriving (Show)

split :: String -> [String]
split line = reverse $ split1 line []
  where
    split1 [] acc = acc
    split1 line acc = let (chars, rest) = break isDigit line in
      split2 rest $ chars:acc
    split2 [] acc = acc
    split2 line acc = let (digits, rest) = span isDigit line in
      split1 rest $ digits:acc

parseCell :: String -> Parsed
parseCell line = case split line of
  ["R", r, "C", c] -> ParsedRC Cell { row = read r, column = read c }
  [c, r]  -> ParsedCR Cell { row = read r, column = fromAbbr c }
  _ -> Unknown line

convert :: Parsed -> String
convert (Unknown x) = x
convert (ParsedCR c) = showRC c
convert (ParsedRC c) = showCR c

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  inputs <- replicateM n getLine
  forM_ inputs $ putStrLn . convert . parseCell

module Main where

import Data.Char
import Control.Monad

data Cell = Cell {
  row :: Int,
  column :: Int
} deriving (Show)

showRC :: Cell -> String
showRC c = "R" <> show (row c) <> "C" <> show (column c)

showCR :: Cell -> String
showCR c = abbr (column c) <> show (row c)

radix = 26

abbr :: Int -> String
abbr x = abbr0 x ""
  where
    abbr0 0 acc = acc
    abbr0 x acc = let y = ord 'A' + (x + 25) `mod` radix in abbr0 (x `div` radix) (chr y:acc)

fromAbbr :: String -> Int
fromAbbr x = fromAbbr0 x 0
  where
    fromAbbr0 [] acc = acc
    fromAbbr0 (a:xs) acc = fromAbbr0 xs $ acc * radix + (ord a - ord 'A' + 1)

data Parsed = ParsedRC Cell
            | ParsedCR Cell
            | Unknown String
  deriving (Show)

headBy :: (a -> Bool) -> [a] -> ([a], [a])
headBy pred line = let match = takeWhile pred line in splitAt (length match) line

split :: String -> [String]
split line = reverse $ split1 line []
  where
    split1 [] acc = acc
    split1 line acc = let (chars, rest) = headBy (not . isDigit) line in
      split2 rest $ chars:acc
    split2 [] acc = acc
    split2 line acc = let (digits, rest) = headBy isDigit line in
      split1 rest $ digits:acc

parseCell :: String -> Parsed
parseCell line = case split line of
  ["R", r, "C", c] -> ParsedRC Cell { row = read r, column = read c }
  [c, r]  -> ParsedCR Cell { row = read r, column = fromAbbr c }
  _ -> Unknown line

convert :: Parsed -> String
convert (Unknown x) = x
convert (ParsedCR c) = showRC c
convert (ParsedRC c) = showCR c

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  inputs <- replicateM n getLine
  forM_ inputs $ putStrLn . convert . parseCell

module Main where

import Data.Char
import Control.Monad

data Cell = Cell {
  row :: Int,
  column :: Int
} deriving (Show)

showRC :: Cell -> String
showRC c = "R" <> show (row c) <> "C" <> show (column c)

showCR :: Cell -> String
showCR c = abbr (column c) <> show (row c)

radix = 26

abbr :: Int -> String
abbr x = abbr0 x ""
  where
    abbr0 0 acc = acc
    abbr0 x acc = let y = ord 'A' + (x `mod` radix) - 1 in abbr0 (x `div` radix) (chr y:acc)

fromAbbr :: String -> Int
fromAbbr x = fromAbbr0 x 0
  where
    fromAbbr0 [] acc = acc
    fromAbbr0 (a:xs) acc = fromAbbr0 xs $ acc * radix + (ord a - ord 'A' + 1)

data Parsed = ParsedRC Cell
            | ParsedCR Cell
            | Unknown String
  deriving (Show)

headBy :: (a -> Bool) -> [a] -> ([a], [a])
headBy pred line = let match = takeWhile pred line in splitAt (length match) line

split :: String -> [String]
split line = reverse $ split1 line []
  where
    split1 [] acc = acc
    split1 line acc = let (chars, rest) = headBy (not . isDigit) line in
      split2 rest $ chars:acc
    split2 [] acc = acc
    split2 line acc = let (digits, rest) = headBy isDigit line in
      split1 rest $ digits:acc

parseCell :: String -> Parsed
parseCell line = case split line of
  ["R", r, "C", c] -> ParsedRC Cell { row = read r, column = read c }
  [c, r]  -> ParsedCR Cell { row = read r, column = fromAbbr c }
  _ -> Unknown line

convert :: Parsed -> String
convert (Unknown x) = x
convert (ParsedCR c) = showRC c
convert (ParsedRC c) = showCR c

main :: IO ()
main = do
  n <- fmap read getLine :: IO Int
  inputs <- replicateM n getLine
  forM_ inputs $ putStrLn . convert . parseCell

import Data.Char

isAbc123 :: String -> Bool
isAbc123 (ch:rest)
    | isAlpha ch    = isAbc123 rest
    | otherwise     = and $ map isDigit rest

an2rc :: String -> String
an2rc an = "R" ++ rowStr ++ "C" ++ (show $ excel2Num 0 colExcel)
            where
                splitAbc123 cur whole@(ch:rest)
                    | isDigit ch    = (cur, whole)
                    | otherwise     = splitAbc123 (cur++[ch]) rest
                (colExcel, rowStr) = splitAbc123 "" an
                excel2Num acc ""        = acc
                excel2Num acc (ch:rest) = excel2Num (acc*26+ord(ch)-ord('A')+1) rest

rc2an :: String -> String
rc2an rc = (excelNota col) ++ rowStr
            where
                stripNums cur (ch:rest)
                    | ch == 'R' = stripNums cur rest
                    | ch == 'C' = (cur, rest)
                    | otherwise = stripNums (cur++[ch]) rest
                (rowStr, colStr) = stripNums "" rc
                col = read colStr :: Int
                excelNota 0 = ""
                excelNota n = (excelNota $ n `div` 26) ++ [chr $ (n-1) `mod` 26 + ord('A')]

convert :: String -> String
convert s
    | isAbc123 s    = an2rc s
    | otherwise     = rc2an s

main :: IO ()
main = do
    t <- (read :: String -> Int) <$> getLine
    run t
        where
            run 0   = return ()
            run n   = do
                coord <- getLine
                putStrLn $ convert coord
                run (n-1)

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
import Data.Char
import Data.List
class Scan a where scan' :: String -> a
instance Scan Int where scan' n = read n
instance Scan Char where scan' (x:_) = x
instance Scan Float where scan' f = read f
instance Scan Double where scan' d = read d
instance Scan Integer where scan' n = read n
instance Scan String where scan' x = x
instance (Scan a,Scan b) => Scan (a,b) where scan' x = scan'' (words x)
                                                 where
                                                   scan'' (x:y:_) = (scan' x,scan' y)
instance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = scan'' (words x)
                                                          where
                                                            scan'' (x:y:z:_) = (scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = scan'' (words x)
                                                                   where
                                                                     scan'' (w:x:y:z:_) = (scan' w,scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = scan'' (words x)
                                                                            where
                                                                              scan'' (v:w:x:y:z:_) = (scan' v,scan' w,scan' x,scan' y,scan' z)
class Ans a where showans :: a -> String
instance Ans Int where showans x = show x
instance Ans Char where showans x = [x]
instance Ans Float where showans x = show x
instance Ans Double where showans x = show x
instance Ans Integer where showans x = show x
instance Ans String where showans x = x
instance (Ans a, Ans b) => Ans (a,b) where
    showans (x,y) = showans x ++ " " ++ showans y
instance (Ans a, Ans b,Ans c) => Ans (a,b,c) where
    showans (x,y,z) = showans x ++ " " ++ showans y ++ " " ++ showans z

scan :: (Scan a) => IO a
scan = do n <- getLine
          return (scan' n)

scans :: (Scan a) => Int -> IO [a]
scans 0 = return []
scans n = do x <- scan
             xs <- scans (n-1)
             return (x:xs)

scanlist :: (Scan a) => IO [a]
scanlist = do l <- getLine
              return [scan' x|x<-words l]

scanlists :: (Scan a) => Int -> IO [[a]]
scanlists 0 = return []
scanlists n = do x <- scanlist :: (Scan a) => IO [a]
                 xs <- scanlists (n-1)
                 return (x:xs)

putAnsLn :: (Ans a) => a -> IO ()
putAnsLn ans = putStrLn (showans ans)

putAnsLns :: (Ans a) => [a] -> IO ()
putAnsLns (x:xs) = do putAnsLn x
                      putAnsLns xs
putAnsLns [] = return ()

putDebugLn :: (Show a) => a -> IO ()
putDebugLn ans = putStrLn (show ans)

inRange :: Ord a => (a,a) -> a -> Bool
inRange (n,m) x = n<=x&&x<=m

isExcel :: String -> Bool
isExcel = null.(dropWhile isDigit).(dropWhile isAlpha)

exceltoRC :: String -> String
exceltoRC str = let (c',r) = span (inRange ('A','Z')) str in
                let c = foldl (\s -> \c -> (ord c)-(ord 'A')+1+s*26) 0 c' in
                ('R':r)++('C':(show c))

rctoExcel :: String -> String
rctoExcel (_:str) = let (r,(_:c')) = span (inRange ('0','9')) str in
                    let c = unfoldr (\x -> if x==0 then Nothing else Just (chr ((mod x 26)+(ord 'A')-1),div x 26)) (read c'::Int) in
                    (reverse c)++r

solve [] = []
solve (x:xs) = (if isExcel x then exceltoRC x else rctoExcel x):solve xs

main = do n <- scan :: IO Int
          l <- scans n ::IO [String]
          putAnsLns (solve l)

{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -O2 #-}
import Data.Char
import Data.List
class Scan a where scan' :: String -> a
instance Scan Int where scan' n = read n
instance Scan Char where scan' (x:_) = x
instance Scan Float where scan' f = read f
instance Scan Double where scan' d = read d
instance Scan Integer where scan' n = read n
instance Scan String where scan' x = x
instance (Scan a,Scan b) => Scan (a,b) where scan' x = scan'' (words x)
                                                 where
                                                   scan'' (x:y:_) = (scan' x,scan' y)
instance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = scan'' (words x)
                                                          where
                                                            scan'' (x:y:z:_) = (scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = scan'' (words x)
                                                                   where
                                                                     scan'' (w:x:y:z:_) = (scan' w,scan' x,scan' y,scan' z)
instance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = scan'' (words x)
                                                                            where
                                                                              scan'' (v:w:x:y:z:_) = (scan' v,scan' w,scan' x,scan' y,scan' z)
class Ans a where showans :: a -> String
instance Ans Int where showans x = show x
instance Ans Char where showans x = [x]
instance Ans Float where showans x = show x
instance Ans Double where showans x = show x
instance Ans Integer where showans x = show x
instance Ans String where showans x = x
instance (Ans a, Ans b) => Ans (a,b) where
    showans (x,y) = showans x ++ " " ++ showans y
instance (Ans a, Ans b,Ans c) => Ans (a,b,c) where
    showans (x,y,z) = showans x ++ " " ++ showans y ++ " " ++ showans z

scan :: (Scan a) => IO a
scan = do n <- getLine
          return (scan' n)

scans :: (Scan a) => Int -> IO [a]
scans 0 = return []
scans n = do x <- scan
             xs <- scans (n-1)
             return (x:xs)

scanlist :: (Scan a) => IO [a]
scanlist = do l <- getLine
              return [scan' x|x<-words l]

scanlists :: (Scan a) => Int -> IO [[a]]
scanlists 0 = return []
scanlists n = do x <- scanlist :: (Scan a) => IO [a]
                 xs <- scanlists (n-1)
                 return (x:xs)

putAnsLn :: (Ans a) => a -> IO ()
putAnsLn ans = putStrLn (showans ans)

putAnsLns :: (Ans a) => [a] -> IO ()
putAnsLns (x:xs) = do putAnsLn x
                      putAnsLns xs
putAnsLns [] = return ()

putDebugLn :: (Show a) => a -> IO ()
putDebugLn ans = putStrLn (show ans)

inRange :: Ord a => (a,a) -> a -> Bool
inRange (n,m) x = n<=x&&x<=m

isExcel :: String -> Bool
isExcel = null.(dropWhile isDigit).(dropWhile isAlpha)

exceltoRC :: String -> String
exceltoRC str = let (c',r) = span (inRange ('A','Z')) str in
                let c = foldl (\s -> \c -> (ord c)-(ord 'A')+1+s*26) 0 c' in
                ('R':r)++('C':(show c))

rctoExcel :: String -> String
rctoExcel (_:str) = let (r,(_:c')) = span (inRange ('0','9')) str in
                    let c = unfoldr (\x -> if x==0 then Nothing else Just (chr ((mod (x+25) 26)+(ord 'A')),div x 26)) (read c'::Int) in
                    (reverse c)++r

solve [] = []
solve (x:xs) = (if isExcel x then exceltoRC x else rctoExcel x):solve xs

main = do n <- scan :: IO Int
          l <- scans n ::IO [String]
          putAnsLns (solve l)

import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    n <- readInt
    inputs <- replicateM n getLine
    mapM_ putStrLn $ parseInputs inputs

parseInputs :: [String] -> [String]
parseInputs [] = []
parseInputs (x:xs) = [spreadSheets x] ++ parseInputs xs

spreadSheets :: String -> String
spreadSheets s = case xs of
    [_,r,_,c] -> rc (read r) (read c)
    [c,r]     -> cr c (read r)

    where xs = groupBy(\a b -> (isDigit a && isDigit b) || (isAlpha a && isAlpha b)) s

cr :: String -> Int -> String
cr c r = "R" ++ (show r) ++ "C" ++ show (conv c)

conv :: String -> Int
conv [] = 1
conv (r:[]) = ord r - ord 'A' + 1
conv (r:rs) = 26^(length rs) * (ord r - ord 'A' + 1) + conv rs

rc :: Int -> Int -> String
rc r c = (inv c) ++ show r

inv :: Int -> String
inv 0 = ""
inv a = inv (a `div` 26) ++ [chr (ord 'A' + (a - 1) `mod` 26)]

readInt :: IO Int
readInt = readLn

import Control.Monad
import Data.List
import Data.Char

main :: IO ()
main = do
    n <- readInt
    inputs <- replicateM n getLine
    mapM_ putStrLn $ parseInputs inputs

parseInputs :: [String] -> [String]
parseInputs [] = []
parseInputs (x:xs) = [spreadSheets x] ++ parseInputs xs

spreadSheets :: String -> String
spreadSheets s = case xs of
    [_,r,_,c] -> rc (read r) (read c)
    [c,r]     -> cr c (read r)

    where xs = groupBy(\a b -> (isDigit a && isDigit b) || (isAlpha a && isAlpha b)) s

cr :: String -> Int -> String
cr c r = "R" ++ (show r) ++ "C" ++ show (conv c)

conv :: String -> Int
conv [] = 1
conv (r:[]) = ord r - ord 'A' + 1
conv (r:rs) = 26^(length rs) * (ord r - ord 'A' + 1) + conv rs

rc :: Int -> Int -> String
rc r c = (inv c) ++ show r

inv :: Int -> String
inv 0 = ""
inv a = inv (((a + 1)`div` 26)) ++ [chr (ord 'A' + (a - 1) `mod` 26)]

readInt :: IO Int
readInt = readLn

import Control.Monad
import Data.Char
import Data.List
import Data.Maybe
import Debug.Trace

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

mapX :: a -> [a -> b] -> [b]
mapX _ [] = []
mapX x (f:fs) = [f x] ++ (mapX x fs)

map2 :: (a -> b -> c) -> [a] -> [b] -> [c]
map2 _ [] [] = []
map2 f (ax:axs) (bx:bxs) = [f ax bx] ++ map2 f axs bxs

isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _  = False

all' :: (a -> Bool) -> [a] -> Bool
all' _ [] = False
all' f l  = all f l

splitByPredicate :: (a -> Bool) -> [a] -> [[a]]
splitByPredicate _ [] = []
splitByPredicate p l
    | p (head l) == True = [takeWhile p l] ++ (splitByPredicate p (dropWhile p l))
    | otherwise          = [takeWhile (not . p) l] ++ (splitByPredicate p (dropWhile (not . p) l))

type CellType = Int

checkCellType :: String -> CellType
checkCellType s
    | length (splitByPredicate isDigit s) == 4 = 1
    | length (splitByPredicate isDigit s) == 2 = 2
    | otherwise                                = error "wrong string!"

fastExp :: Int -> Int -> Int
fastExp x 0 = 1
fastExp x 1 = x
fastExp x a
    | even a     = lexp * lexp
    | odd a      = lexp * lexp * a
    where
        lexp = fastExp (x * x) (div a 2)

colStr2Inth :: String -> Int
colStr2Inth [] = 0
colStr2Inth s  = (colStr2Inth $ init s) * 26 + (ord (last s) - ord 'A')

colStr2Int :: String -> Int
colStr2Int s = sum (map (fastExp 26) [0 .. (length s - 1)]) + colStr2Inth s

convertCellType2To1 :: String -> String
convertCellType2To1 s =
    let sp = splitByPredicate isDigit s
    in "R" ++ (sp !! 1) ++ "C" ++ (show $ colStr2Int (sp !! 0))

colInt2Strhh :: Int -> String
colInt2Strhh n
    | n < 26    = [chr (ord 'A' + n)]
    | otherwise = (colInt2Strhh (div n 26)) ++ (colInt2Strhh (mod n 26))

colInt2Strh :: Int -> Int -> String
colInt2Strh n l =
    let hresult = colInt2Strhh n
    in (replicate (l - length hresult)) 'A' ++ hresult

colInt2Str :: Int -> String
colInt2Str n =
    let powList = map (fastExp 26) [0 .. 100]
        sumPowList = scanl1 (+) powList
        fi = fromJust (findIndex (<0) (map2 (-) (replicate 100 n) sumPowList))
    in colInt2Strh (n - (sumPowList !! (fi - 1))) (fi)

convertCellType1To2 :: String -> String
convertCellType1To2 s =
    let sp = splitByPredicate isDigit s
    in colInt2Str (read (sp !! 3) :: Int) ++ (sp !! 1)

convertCellType :: String -> String
convertCellType s
    | checkCellType s == 1 = convertCellType1To2 s
    | checkCellType s == 2 = convertCellType2To1 s

main = do
    sn <- getLine
    let n = read sn :: Int
    sl <- getLines n
    putStrLn $ unlines (map convertCellType sl)

import Control.Monad
import Data.Char
import Data.List
import Data.Maybe
import Debug.Trace

getLines :: Int -> IO [String]
getLines n = replicateM n getLine

mapX :: a -> [a -> b] -> [b]
mapX _ [] = []
mapX x (f:fs) = [f x] ++ (mapX x fs)

map2 :: (a -> b -> c) -> [a] -> [b] -> [c]
map2 _ [] [] = []
map2 f (ax:axs) (bx:bxs) = [f ax bx] ++ map2 f axs bxs

isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _  = False

all' :: (a -> Bool) -> [a] -> Bool
all' _ [] = False
all' f l  = all f l

splitByPredicate :: (a -> Bool) -> [a] -> [[a]]
splitByPredicate _ [] = []
splitByPredicate p l
    | p (head l) == True = [takeWhile p l] ++ (splitByPredicate p (dropWhile p l))
    | otherwise          = [takeWhile (not . p) l] ++ (splitByPredicate p (dropWhile (not . p) l))

type CellType = Int

checkCellType :: String -> CellType
checkCellType s
    | length (splitByPredicate isDigit s) == 4 = 1
    | length (splitByPredicate isDigit s) == 2 = 2
    | otherwise                                = error "wrong string!"

fastExp :: Int -> Int -> Int
fastExp x 0 = 1
fastExp x 1 = x
fastExp x a
    | even a     = lexp * lexp
    | odd a      = lexp * lexp * a
    where
        lexp = fastExp x (div a 2)

colStr2Inth :: String -> Int
colStr2Inth [] = 0
colStr2Inth s  = (colStr2Inth $ init s) * 26 + (ord (last s) - ord 'A')

colStr2Int :: String -> Int
colStr2Int s = sum (map (fastExp 26) [0 .. (length s - 1)]) + colStr2Inth s

convertCellType2To1 :: String -> String
convertCellType2To1 s =
    let sp = splitByPredicate isDigit s
    in "R" ++ (sp !! 1) ++ "C" ++ (show $ colStr2Int (sp !! 0))

colInt2Strhh :: Int -> String
colInt2Strhh n
    | n < 26    = [chr (ord 'A' + n)]
    | otherwise = (colInt2Strhh (div n 26)) ++ (colInt2Strhh (mod n 26))

colInt2Strh :: Int -> Int -> String
colInt2Strh n l =
    let hresult = colInt2Strhh n
    in (replicate (l - length hresult)) 'A' ++ hresult

colInt2Str :: Int -> String
colInt2Str n =
    let powList = map (fastExp 26) [0 .. 100]
        sumPowList = scanl1 (+) powList
        fi = fromJust (findIndex (<0) (map2 (-) (replicate 100 n) sumPowList))
    in colInt2Strh (n - (sumPowList !! (fi - 1))) (fi)

convertCellType1To2 :: String -> String
convertCellType1To2 s =
    let sp = splitByPredicate isDigit s
    in colInt2Str (read (sp !! 3) :: Int) ++ (sp !! 1)

convertCellType :: String -> String
convertCellType s
    | checkCellType s == 1 = convertCellType1To2 s
    | checkCellType s == 2 = convertCellType2To1 s

main = do
   {- putStrLn $ show $ fastExp 26 2
    putStrLn $ show (scanl1 (+) (map (fastExp 26) [0 .. 20]))-}
    sn <- getLine
    let n = read sn :: Int
    sl <- getLines n
    putStrLn $ unlines (map convertCellType sl)

import Data.Char
import Data.List

main = interact $ unlines . map conv . tail . lines

conv s = to arr
    where arr = groupBy (\a b -> isDigit a == isDigit b) s

to [c, r] = "R" ++ r ++ "C" ++ (show . toRCcolumn $ c)
to [_, r, _, c] = (reverse . toXYcolumn . read $ c) ++ r

toRCcolumn = foldl (\acc d -> 26 * acc + ord d - ord 'A' + 1) 0

toXYcolumn 0 = []
toXYcolumn c = (chr (cmod + ord 'A' - 1)) : toXYcolumn cdiv
    where (cdiv, cmod) = c `divMod` 26

module Main where

import Control.Monad
import Control.DeepSeq
import Data.Function
import Data.List
import Data.Char

--import Debug.Trace

type AlphaNum = String -- little endian

str2an = reverse
an2str = reverse

data Numeration = T1 String Int | T2 Int Int

instance Show Numeration where
    show (T1 col row) = col ++ show row
    show (T2 row col) = "R" ++ show row ++ "C" ++ show col

isT2 (r:x:cy) = (r == 'R') && isDigit x && ('C' `elem` cy)
isT2 _ = False

toT1 str = T1 col (read row) where
    (col, row) = span isLetter str

toT2 str = T2 (read row) (read col) where
    (r:row, c:col) = span ((/=) 'C') str

convertType (T1 col row) = T2 row (atoi col)
convertType (T2 row col) = T1 (itoa col) row

-- 'i' is 0-index
atoi [] = 0
atoi str = (ord x - ord 'A' + 1) + (26 * atoi xs) where
    x = last str
    xs = init str

itoc i = chr (ord 'A' + i - 1)
itoa i
    | i < 26 = [itoc i]
    | otherwise = itoa q' ++ [itoc r'] where
        (q, r) = i `divMod` 26
        (q', r') = if r == 0 then (q-1, 26) else (q, r)

process :: String -> String
process str = show numeration' where
    numeration = if isT2 str then toT2 str else toT1 str
    numeration' = convertType numeration

printLines = fmap head . sequence . map putStrLn

main = do
    n <- read <$> getLine
    lines <- replicateM n getLine
    printLines (map process lines)

module Main where

import Control.Monad
import Data.List
import Data.Char
--import Debug.Trace

data Numeration = T1 String Int | T2 Int Int

instance Show Numeration where
    show (T1 col row) = col ++ show row
    show (T2 row col) = "R" ++ show row ++ "C" ++ show col

isT2 (r:x:cy) = (r == 'R') && isDigit x && ('C' `elem` cy)
isT2 _ = False

toT1 str = T1 col (read row) where
    (col, row) = span isLetter str

toT2 str = T2 (read row) (read col) where
    (r:row, c:col) = span ((/=) 'C') str

convertType (T1 col row) = T2 row (atoi col + 1)
convertType (T2 row col) = T1 (itoa (col - 1)) row

-- 'i' is 0-index

atoi [] = 0
atoi str = (ord x - ord 'A') + (26 * atoi xs) where
    x = last str
    xs = init str

itoc i = chr (ord 'A' + i)
itoa i
    | i < 26 = [itoc i]
    | otherwise = itoa q ++ [itoc r] where
        (q, r) = i `divMod` 26

process :: String -> String
process str = show numeration' where
    numeration = if isT2 str then toT2 str else toT1 str
    numeration' = convertType numeration

printLines = fmap head . sequence . map putStrLn

main = do
    n <- read <$> getLine
    lines <- replicateM n getLine
    printLines (map process lines)

import Data.Char
import Data.List

intToStr 0 = []
intToStr x = chr ( ( x `mod` 26 ) + ord 'A' - 1 ) : intToStr ( x `div` 26 )

strToInt = foldl ( \ x y -> 26 * x + ord y - ord 'A' + 1 ) 0

solve str =
	case parse str of
		[_,r,_,c] -> ( reverse . intToStr . read $ c ) ++ r
		[c,r] -> "R" ++ r ++ "C" ++ ( show . strToInt $ c )
	where parse = groupBy ( \ a b -> isDigit a == isDigit b )

main = interact $ unlines . map solve . tail . lines

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n == 0 = ""
  | otherwise = n2a (n `div` 26) ++ [c (n `mod` 26)]
  where
    c x = chr (ord 'A' + x + 1)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n > 26   = c (n `div` 26) : n2a (n `mod` 26)
  | otherwise = [c n]
  where
    c x = chr (ord 'A' + x - 1)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n > 26   = n2a (n `div` 26) ++ [c (n `mod` 26)]
  | otherwise = [c n]
  where
    c x = chr (ord 'A' + x - 1)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n > 26   = n2a (n `div` 27) ++ [c (n `mod` 27)]
  | otherwise = [c n]
  where
    c x = chr (ord 'A' + x + 1)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.List

a2n :: String -> Int
a2n s = a2n' s 0
  where
    a2n'     [] acc = acc
    a2n' (x:xs) acc = a2n' xs (26 * acc + (ord x - ord 'A' + 1))

n2a :: Int -> String
n2a n
  | n == 0 = ""
  | otherwise = n2a (n `div` 26) ++ [c (n `mod` 26)]
  where
    c x = chr (ord 'A' + x - 1)

-- R23C55 => BC23
toYX :: String -> String -> String
toYX row col = (n2a $ (read col :: Int)) ++ row

-- BC23 => R23C55
toRXCY :: String-> String -> String
toRXCY col row = "R" ++ row ++ "C" ++ c
  where
    c = show $ a2n col

calc :: String -> String
calc s = case length xs of
           2 -> toRXCY (xs!!0) (xs!!1)
           4 -> toYX   (xs!!1) (xs!!3)
           _ -> error "invalid length"
  where
    xs = groupBy (\a b -> (isAlpha a && isAlpha b) || (isDigit a && isDigit b)) s

doLine :: Int -> IO ()
doLine 0 = return ()
doLine n = do s <- getLine
              putStrLn $ calc s
              doLine (n-1)

main = do s <- getLine
          let n = read s :: Int
          doLine n

import Data.Char
import Data.Function
import Data.List

fromBase26 :: String->Int
-- 64 = 'A' - 1
fromBase26 s = foldl (\acc c->acc*26 + ord c -64) 0 s

toBase26::Int->String
toBase26 i = if i == 0
             then []
             else  toBase26 (i `div` 26) ++ return (chr (i `mod` 26 + 64))

parseSplit input = groupBy ((==) `on` isAlpha) input

transform :: [String] -> String
transform [_, r, _, c] = toBase26  (read c::Int) ++ r
transform [c, r] = "R" ++ r ++ "C" ++ show (fromBase26 c)

act :: IO()
act = do
    s<-getLine
    putStrLn $ transform $ parseSplit s

main = do
    s<-getLine
    let testNum = read s::Int
    mapM_ (\x->act) $take testNum[1..]
    return ()

import Data.Char

data CharType = Alpha | Digit | Unknown
  deriving (Eq)

data CellFormat = ABC123 | RXCY
  deriving (Show)
data CellRef = CellRef {
  row :: Integer,
  column :: Integer
} deriving (Show)

charType :: Char -> CharType
charType c | isDigit c = Digit
           | isAlpha c = Alpha
           | otherwise = Unknown

split :: String -> [String]
split s = reverse (split2 s [])

split2 :: String -> [String] -> [String]
split2 [] xs = xs
split2 (c:cs) [] = split2 cs [[c]]
split2 (c:cs) (x:xs) | charType c == charType (head x) = split2 cs ((x ++ [c]):xs)
                     | otherwise = split2 cs ([c]:x:xs)

readColumnRef :: String -> Integer
readColumnRef s = readColumnRef2 0 s
  where readColumnRef2 v [] = v
        readColumnRef2 v (x:xs) = readColumnRef2 (v*26 + toInteger (ord (toUpper x) - ord 'A' + 1)) xs

showColumnRef :: Integer -> String
showColumnRef x = showColumnRef2 "" x
  where showColumnRef2 :: String -> Integer -> String
        showColumnRef2 [] 0 = "0"
        showColumnRef2 s 0 = s
        showColumnRef2 s x = showColumnRef2 ([chr ((fromIntegral (x `mod` 26)) + ord 'A' - 1)] ++ s) (x `div` 26)

readCellRef :: String -> (CellRef, CellFormat)
readCellRef s = case (split s) of
  ("R":x:"C":y:[]) -> (CellRef (read x) (read y), RXCY)
  (a:x:[]) | (charType (head a) == Alpha) && (charType (head x) == Digit) -> (CellRef (read x) (readColumnRef a), ABC123)
  _ -> error "Invalid cell reference format"

showCellRef :: CellRef -> CellFormat -> String
showCellRef c ABC123 = (showColumnRef (column c)) ++ (show (row c))
showCellRef c RXCY = "R" ++ (show (row c)) ++ "C" ++ (show (column c))

convert :: String -> String
convert s = case (readCellRef s) of
  (c, ABC123) -> showCellRef c RXCY
  (c, RXCY) -> showCellRef c ABC123

solve :: IO ()
solve = getLine >>= (putStrLn . convert)

solveN :: Int -> IO ()
solveN 1 = solve
solveN n = do
  solve
  solveN (n-1)

main = getLine >>= (solveN . read)

import Data.Char

data CharType = Alpha | Digit | Unknown
  deriving (Eq)

data CellFormat = ABC123 | RXCY
  deriving (Show)
data CellRef = CellRef {
  row :: Integer,
  column :: Integer
} deriving (Show)

charType :: Char -> CharType
charType c | isDigit c = Digit
           | isAlpha c = Alpha
           | otherwise = Unknown

stringType :: String -> CharType
stringType s = charType (head s)

split :: String -> [String]
split s = reverse (split2 s [])

split2 :: String -> [String] -> [String]
split2 [] xs = xs
split2 (c:cs) [] = split2 cs [[c]]
split2 (c:cs) (x:xs) | charType c == charType (head x) = split2 cs ((x ++ [c]):xs)
                     | otherwise = split2 cs ([c]:x:xs)

readColumnRef :: String -> Integer
readColumnRef s = readColumnRef2 0 s
  where readColumnRef2 v [] = v
        readColumnRef2 v (x:xs) = readColumnRef2 (v*26 + toInteger (ord (toUpper x) - ord 'A' + 1)) xs

showColumnRef :: Integer -> String
showColumnRef x = showColumnRef2 "" x
  where showColumnRef2 :: String -> Integer -> String
        showColumnRef2 [] 0 = "A"
        showColumnRef2 s 0 = s
        showColumnRef2 s x = showColumnRef2 ([chr ((fromIntegral ((x-1) `mod` 26)) + ord 'A')] ++ s) (x `div` 26)

readCellRef :: String -> (CellRef, CellFormat)
readCellRef s = case (split s) of
  ("R":x:"C":y:[]) ->
    (CellRef (read x) (read y), RXCY)
  (a:x:[]) | (stringType a == Alpha) && (stringType x == Digit) ->
    (CellRef (read x) (readColumnRef a), ABC123)
  _ -> error "Invalid cell reference format"

showCellRef :: CellRef -> CellFormat -> String
showCellRef c ABC123 = (showColumnRef (column c)) ++ (show (row c))
showCellRef c RXCY = "R" ++ (show (row c)) ++ "C" ++ (show (column c))

convert :: String -> String
convert s = case (readCellRef s) of
    (c, ABC123) -> showCellRef c RXCY
    (c, RXCY) -> showCellRef c ABC123

solve :: IO ()
solve = getLine >>= (putStrLn . convert)

solveN :: Int -> IO ()
solveN 1 = solve
solveN n = do
  solve
  solveN (n-1)

main = getLine >>= (solveN . read)

import Data.Char

data CharType = Alpha | Digit | Unknown
  deriving (Eq)

data CellFormat = ABC123 | RXCY
  deriving (Show)
data CellRef = CellRef {
  row :: Integer,
  column :: Integer
} deriving (Show)

charType :: Char -> CharType
charType c | isDigit c = Digit
           | isAlpha c = Alpha
           | otherwise = Unknown

split :: String -> [String]
split s = reverse (split2 s [])

split2 :: String -> [String] -> [String]
split2 [] xs = xs
split2 (c:cs) [] = split2 cs [[c]]
split2 (c:cs) (x:xs) | charType c == charType (head x) = split2 cs ((x ++ [c]):xs)
                     | otherwise = split2 cs ([c]:x:xs)

readColumnRef :: String -> Integer
readColumnRef s = readColumnRef2 0 s
  where readColumnRef2 v [] = v
        readColumnRef2 v (x:xs) = readColumnRef2 (v*26 + toInteger (ord (toUpper x) - ord 'A' + 1)) xs

showColumnRef :: Integer -> String
showColumnRef x = showColumnRef2 "" x
  where showColumnRef2 :: String -> Integer -> String
        showColumnRef2 [] 0 = "0"
        showColumnRef2 s 0 = s
        showColumnRef2 s x = showColumnRef2 ([chr ((fromIntegral (x `mod` 26)) + ord 'A' - 1)] ++ s) (x `div` 26)

readCellRef :: String -> (CellRef, CellFormat)
readCellRef s = case (split s) of
  ("R":x:"C":y:[]) -> (CellRef (read x) (read y), RXCY)
  (a:x:[]) | (charType (head a) == Alpha) && (charType (head x) == Digit) -> (CellRef (read x) (readColumnRef a), ABC123)
  _ -> error "Invalid cell reference format"

showCellRef :: CellRef -> CellFormat -> String
showCellRef c ABC123 = (showColumnRef (column c)) ++ (show (row c))
showCellRef c RXCY = "R" ++ (show (row c)) ++ "C" ++ (show (column c))

convert :: String -> String
convert s = case (readCellRef s) of
  (c, ABC123) -> showCellRef c RXCY
  (c, RXCY) -> showCellRef c ABC123

solve :: IO ()
solve = getLine >>= (print . convert)

solveN :: Int -> IO ()
solveN 1 = solve
solveN n = do
  solve
  solveN (n-1)

main = getLine >>= (solveN . read)

import Data.Char

data CharType = Alpha | Digit | Unknown
  deriving (Eq)

data CellFormat = ABC123 | RXCY
  deriving (Show)
data CellRef = CellRef {
  row :: Integer,
  column :: Integer
} deriving (Show)

charType :: Char -> CharType
charType c | isDigit c = Digit
           | isAlpha c = Alpha
           | otherwise = Unknown

split :: String -> [String]
split s = reverse (split2 s [])

split2 :: String -> [String] -> [String]
split2 [] xs = xs
split2 (c:cs) [] = split2 cs [[c]]
split2 (c:cs) (x:xs) | charType c == charType (head x) = split2 cs ((x ++ [c]):xs)
                     | otherwise = split2 cs ([c]:x:xs)

readColumnRef :: String -> Integer
readColumnRef s = readColumnRef2 0 s
  where readColumnRef2 v [] = v
        readColumnRef2 v (x:xs) = readColumnRef2 (v*26 + toInteger (ord (toUpper x) - ord 'A' + 1)) xs

showColumnRef :: Integer -> String
showColumnRef x = showColumnRef2 "" x
  where showColumnRef2 :: String -> Integer -> String
        showColumnRef2 [] 0 = "0"
        showColumnRef2 s 0 = s
        showColumnRef2 s x = showColumnRef2 ([chr ((fromIntegral (x `mod` 26)) + ord 'A' - 1)] ++ s) (x `div` 26)

readCellRef :: String -> (CellRef, CellFormat)
readCellRef s = case (split s) of
  ("R":x:"C":y:[]) -> (CellRef (read x) (read y), RXCY)
  (a:x:[]) | (charType (head a) == Alpha) && (charType (head x) == Digit) -> (CellRef (readColumnRef a) (read x), ABC123)
  _ -> error "Invalid cell reference format"

showCellRef :: CellRef -> CellFormat -> String
showCellRef c ABC123 = (showColumnRef (column c)) ++ (show (row c))
showCellRef c RXCY = "R" ++ (show (row c)) ++ "C" ++ (show (column c))

convert :: String -> String
convert s = case (readCellRef s) of
  (c, ABC123) -> showCellRef c RXCY
  (c, RXCY) -> showCellRef c ABC123

solve :: IO ()
solve = getLine >>= (print . convert)

solveN :: Int -> IO ()
solveN 1 = solve
solveN n = do
  solve
  solveN (n-1)

main = getLine >>= (solveN . read)

module Main where

import Data.List (groupBy)

getInt :: IO Int
getInt = readLn

processInput :: Int -> String -> String
processInput n = unlines . map processLine . take n . lines

processLine :: String -> String
processLine line = case (map tail $ groupBy (\a b -> b /= 'C') line) of
  [r, c] -> convert (read c) ++ r

convert :: Int -> String
convert n = if n <= 26
  then [['A'..'Z'] !! (n - 1)]
  else case quotRem n 26 of
    (q, r) -> (convert q) ++ (convert r)

main = do
  n <- getInt
  interact $ processInput n