object P1B {
    import io.StdIn._

    val alNum = "([A-Z]+)([0-9]+)".r
    val rc = "R([0-9]+)C([0-9]+)".r

    def main(args : Array[String]) {
        for (_ <- 1 to readInt) readLine match {
            case alNum(al, num) => {
                print("R")
                print(num)
                print("C")
                println(al.map{_ - 'A' + 1}.reduce{_ * 26 + _})
            }
            case rc(r, c) => {
                def f(n:Int, s:StringBuilder):StringBuilder = {
                    if (n == 0) return s
                    val nN = (n - 1) / 26
                    f(nN, s += ('A' - 1 + n - nN * 26).toChar)
                }
                print(f(c.toInt, new StringBuilder).reverse)
                println(r)
            }
        }
    }
}

/**
 * Created by gzq on 15-4-4.
 */
object CF1B {
  def letters2Numbers(str: String): Int = {
    str.map(letter => letter - 'A' + 1).reduceLeft((sum, ele) => sum * 26 + ele)
  }

  def numbers2Letters(strNum: String): String = {
    val aLessOne = 'A' - 1
    var num = strNum.toInt
    var result = ""
    while (num != 0) {
      val remainder = num % 26
      if (remainder != 0) {
        result = (remainder + aLessOne).toChar + result
        num /= 26
      } else {
        result = 'Z' + result
        num = num / 26 - 1
      }
    }
    return result
  }

  def main(args: Array[String]) {
    val in = scala.io.StdIn
    val count = in.readInt()

    // Define patters
    // pattern1 matches strings like BC23
    // pattern2 matches strings like R23C55
    val pattern1 = """([a-zA-Z]+)(\d+)""".r
    val pattern2 = """R(\d+)C(\d+)""".r

    for (i <- 1 to count) {
      val line = in.readLine()

      line match {
        case pattern1(column, row) => println("R" + row + "C" + letters2Numbers(column))
        case pattern2(row, column) => println(numbers2Letters(column) + row)
      }
    }
  }
}

import java.util.Scanner

object Solution {
  def main(args: Array[String]): Unit = {

    val scanner = new Scanner(System.in)
    val n = scanner.nextInt()
    for (i <- 0 until n) {
      val str = scanner.next().toUpperCase
      println({
        if (isNormal(str))
          toReverse(str)
        else
          toNormal(str)
      }.toUpperCase)
    }

  }

  def toReverse(str: String): String = {
    val index = str.indexOf("C")
    toSymbol(str.substring(index + 1)) + str.substring(1, index)
  }

  def toNormal(str: String): String = {
    var columnNumber = ""
    var rowNumber = ""
    for (s <- str)
      if (s.isDigit)
        rowNumber = rowNumber + s
      else
        columnNumber = columnNumber + s

    "R" + rowNumber + "C" + toDec(columnNumber)
  }

  def toSymbol(str: String) = {
    var value = Integer.parseInt(str)
    var result = ""
    while (value > 0) {
      var remainder = value % 26
      var whole = value / 26

      if (remainder == 0) {
        whole = whole - 1
        remainder = 26
      }

      result = getSymbol(remainder) + result
      value = whole
    }

    result
  }

  def toDec(str: String): String = {
    var result = 0
    for ((s, i) <- str.reverse.zipWithIndex)
      result = result + getNumber(s) * Math.pow(26, i).toInt

    result.toString
  }

  def getSymbol(number: Int): String = ('A' - 1 + number).toChar.toString

  def getNumber(s: Char) = 26 - ('Z' - s)

  def isNormal(str: String): Boolean = str.matches("^R[\\d]+C[\\d]+$")
}

import scala.collection.mutable._
import scala.math._
object B extends App {
  def isRXCY(s: String): Boolean = {
    if(s.length < 4) return false
    s.count(_ == 'R') == 1 && s.count(_ == 'C') == 1 && s(1).isDigit
  }
  def toExcel(s: String): String = {
    val r = s.slice(s.indexOf('R')+1, s.indexOf('C')).toInt
    val c = s.drop(s.indexOf('C')+1).toInt
    def toAlph(v: Int): String = {
      if(v == 0) return ""
      val d = if(v % 26 - 1 == -1) 25 else v % 26 - 1
      ('A' + d).toChar + toAlph((v - d)/26)
    }
    toAlph(c).reverse + r
  }
  def toRXCY(s: String): String = {
    def toI(s: String, i: Int): Int = {
      if(s.length == 0) return 0
      ((s.last - 'A' + 1) * i) + toI(s.dropRight(1), i * 26)
    }
    val R = """([A-Z]*)([0-9]*)""".r
    s match {
      case R(c,r) =>
        "R" + r + "C" + toI(c,1)
      case _ => null
    }
  }
  val n = readLine.toInt
  for(i <- 0 until n) {
    val s = readLine
    println(
      if(isRXCY(s)) toExcel(s)
      else          toRXCY(s)
    )
  }
}

object spreadsheets extends App {
  val chars = ('A' to 'Z').toArray
  val RC = "R([0-9]+)C([0-9]+)".r
  val CR = "([A-Z]+)([0-9]+)".r

  def toCR(r: Int, c: Int) = {
    def c2s(c: Int): String =
      if(c > 0) c2s((c - 1) / 26) + chars((c - 1) % 26)
      else ""
    c2s(c) + r
  }
  def toRC(c: String, r: Int) = {
    val ci = c.foldLeft(0) { (l, c) => (l * 26) + (c - 'A' + 1) }
    s"R${r}C${ci}"
  }

  for(i <- 1 to readInt) readLine match {
    case RC(r, c) => println(toCR(r.toInt, c.toInt))
    case CR(c, r) => println(toRC(c, r.toInt))
    //case l => println(s"ERROR: $l")
  }
}

import java.util.Scanner

object B {
  def RC2Normal(r: String, c_str: String): String = {
    val c = c_str.toInt
    val (left, len) = Iterator.iterate((c, 1, 1)){p =>
        val (c_left, count, step) = p
        (c_left - step * 26, count + 1, step * 26)
      }.find(p => p._1 <= 0) match {
        case Some(x) => (x._1 + x._3, x._2 - 1)
	case None => (-1, -2)
      }
    val c_converted = ((left - 1, "") /:(1 to len)){(p, i) =>
      (p._1 / 26, ('A'.toInt + (p._1 % 26)).toChar + p._2)}._2
    "%s%s".format(c_converted, r)
  }

  def Normal2RC(c_str: String, r:String): String = {
    val base = (1 to c_str.length).foldLeft(0)((a, b)=>a * 26 + 1)
    val diff = (0 /: c_str) ((s, c)=>s * 26 + c.toInt - 'A'.toInt)
    val c = base + diff
    "R%sC%d".format(r, c)
  }

  def conv(line: String): String = {
    val p_rc = """^R(\d+)C(\d+)$""".r
    val p_norm = """^([A-Z]+)(\d+)$""".r
    return p_rc findFirstIn line match {
      case Some(p_rc(r, c)) => RC2Normal(r, c)
      case None => p_norm findFirstIn line match {
        case Some(p_norm(c, r)) => Normal2RC(c, r)
	case None => "Error"
      }
    }
  }

  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val count = sc.nextInt
    sc.nextLine // skip newline
    for (i <- 1 to count) {
      val line = sc.nextLine
      println(conv(line))
    }
  }
}

object Solution extends App {
  val f = "^R(\\d+)C(\\d+)$".r
  val s = "^([A-Z]+)(\\d+)$".r

  def strToVal(n: String): Int = n.foldLeft(0){
      case (acc, el) => acc * 26 + (el - 'A' + 1)
    }

  def valToStr(n: Int): String = {
    n match {
      case 0 => ""
      case t =>
        var ans = List.empty[Char]
        var x = t - 1
        while (x >= 26) {
          ans = ('A' + x % 26).toChar :: ans
          x = x / 26 - 1
        }
        ans = ('A' + x % 27).toChar :: ans
        ans.mkString
    }
  }

  def strToInt(n: String): String = n match {
    case f(row, column) =>
//      println("Row " + row + " column " + column)
//      (row.toInt, column.toInt)
      s"${valToStr(column.toInt)}$row"
    case s(column, row) =>
//      (strToVal(row), column.toInt)
      s"R${row}C${strToVal(column)}"
  }

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
//  println(strToInt("RZ228"))
//  println(strToInt("RI228"))
//  println(strToInt("R228C494"))
//  println(valToStr(1))
//  println(valToStr(26))
//  println(valToStr(27))
//  println(valToStr(28))
//  Range(1, 1000).foreach(i => println(valToStr(i)))
  println(Range(0, n).map(_ => strToInt(in.next())).mkString("\n"))
//  println(min + " " + max)
}

object cf1B {
	import java.util.Scanner
	val sc = new Scanner(System.in)
	def main(args : Array[String]) : Unit = {
		val n = sc.nextInt
//		println(rechange("BA23"))
//		println(change("R23C55"))
		for(i <- 1 to n){
			val st = sc.next
			if(st(0)=='R' && st(1).isDigit && st.contains('C'))
				println(change(st))
			else
				println(rechange(st))
		}
	}
	def change(st:String):String = {
		val (s1,s2) = (st drop 1 ) span (_.isDigit)
		var num = 0
		s2 drop 1 foreach(c => (num*=10,num+=c.toInt-'0'))
		var s=""
		while(num>0){
			val mod = num%26
			num/=26
			s+=('A'-1 + ( if(mod==0) {num-=1;26} else mod)).toChar
		}
		s.reverse+s1
	}
	def rechange(st:String):String = {
		val (s1,s2) = st.span(c => c.isLetter)
		var sum = 0
		s1 foreach (c =>(sum*=26,sum=sum+(c.toInt-'A'.toInt+1)))
		"R"+s2+"C"+sum
	}

}

import scala.collection.mutable.ListBuffer

object B1ExcelTables extends App {

  val scanner = new java.util.Scanner(System.in)

  var items = ListBuffer.empty[String]

  val size = scanner.nextInt()

  (1 until (size + 1)).foreach(item => items += scanner.next())

  val pattern = """R[0-9]+C[0-9]+""".stripMargin

  solve()

  def solve() {
    items.foreach {
      item =>
        if (item.matches(pattern)) solveReverse(item) else solveStraight(item)
    }
  }

  def solveReverse(item: String): Unit = {
    val splits = item.split("R|C")
    val rowNum = splits(1)
    var colNum = splits(2).toLong
    val res = new StringBuilder()
    var exp = 1

    def solveRev(prevPow: Long, pow: Long):Unit = {
      val cnt = colNum % pow
      if (pow <= colNum) {
        if (cnt == 0) {
          res += 'Z'
          colNum -= pow
        } else {
          res += (cnt / prevPow + 64).toChar
          colNum -= cnt
        }
        exp += 1
        solveRev(pow, pow * 26)
      } else if (pow > colNum && cnt != 0) {
        res += (colNum / prevPow + 64).toChar
      }
    }

    solveRev(1, 26)
    println(res.reverse + rowNum)
  }

  def solveStraight(item: String) = {
    val (row, col) = item.splitBy(_.isDigit)
    val colNum = col.reverse.zipWithIndex.foldLeft(0)((acc, ch) => {
      acc + (ch._1.toInt - 64) * scala.math.pow(26, ch._2).toInt
    })
    println("R" + row + "C" + colNum)
  }

  implicit class StringOps(input: String) {

    def splitBy(predicate: (Char) => Boolean): (String, String) = {
      val first = new StringBuilder()
      val second = new StringBuilder()
      input.foreach {
        ch =>
          if (predicate(ch)) first += ch else second += ch
      }
      (first.toString(), second.toString())
    }

  }

}

object B1 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def baseAlphatoInt(a: String): Long = {
    var res = 0L
    for(i <- 0 until a.length) {
      res *= 26
      res += a(i)-'A'+1
    }
    res
  }
  def baseIntToAlpha(a: Int): String = {
    var num = a
    var res = ""
    while(num > 0) {
      if(num%26 == 0) {
        res = 'Z' + res
        num -= 1
      } else {
        res = ((num % 26) + 'A' - 1).toChar + res
      }
      num /= 26
    }
    res
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val reg1 = """R(\d+)C(\d+)""".r
    val reg2 = """([A-Z]+)(\d+)""".r

    for(_ <- 0 until n) {
      val input = read
      val ret = reg1.findFirstMatchIn(input) match {
        case Some(m) =>
          s"${baseIntToAlpha(m.group(2).toInt)}${m.group(1)}"
        case None =>
          reg2.findFirstMatchIn(input) match {
            case Some(m) =>
              s"R${m.group(2)}C${baseAlphatoInt(m.group(1))}"
            case None =>
              "parsing failed"
          }
      }
      println(ret)
    }
  }
}

import java.util.Scanner
import scala.collection.mutable.ListBuffer
object ETables extends App {

  val scanner = new Scanner(System.in)
  val lb = new ListBuffer[String]

  val asciiOffset = 64 // A-1
  val base = 26

  while (scanner.hasNextLine) lb.append(scanner.nextLine().toUpperCase)
  val input = lb.toList.tail

  def basePower(i: Int): Int = {
    def helper(p: Int, acc: Int): Int = {
      if (p == 0) 1 * acc
      else helper(p-1, acc*base)
    }
    helper(i, 1)
  }

  def transform2Number(col: String): Int = {
    def helper(c: String, iter: Int, acc: Int): Int =
      if (c.isEmpty) acc
      else helper(c.substring(1), iter+1, acc + (c.charAt(0) - asciiOffset) * basePower(iter))
    helper(col.reverse, 0, 0)
  }

  def transform2String(col: Int): String = {
    def mod2Char(m: Int): Char = if (m == 0) (asciiOffset+base).toChar else (asciiOffset + m).toChar
    def helper(c: Int, acc: String): String = {
      if (c == 0) acc
      else if (c % base == 0) helper(c / base - 1, acc + mod2Char(0))
      else helper(c / base, acc + mod2Char(c%base))
    }
    helper(col,"").reverse
  }

  def transform(s: String): String = {
    if (s matches """^R\d+C\d+$""") transform2String(s.substring(s.indexOf('C')+1).toInt) + s.substring(1, s.indexOf('C'))
    else "R" + """\d+""".r.findFirstMatchIn(s).get + "C" + transform2Number("""^\D+""".r.findFirstMatchIn(s).get.toString())
  }

  input.foreach(s => println(transform(s)))
}

/**
 * Created by yangchaozhong on 3/8/15.
 */
object CF1B extends App {
  import java.io.{PrintWriter}
  import java.util.{Scanner}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def isAType(s: String) = {
    s.matches("R\\d+C\\d+")
  }

  def transform(s: String) = {
    if (s.matches("[A-Z]+")) {
      var res = 0
      val rs = s.reverse
      (0 to (rs.length - 1)).foreach { i =>
        res += (rs.charAt(i) - 'A' + 1) * Math.pow(26, i).toInt
      }
      res
    } else {
      var res = ""

      var n = s.toInt
      while (n > 0) {
        var m = n % 26
        if (m == 0) m = 26
        res += (m + 64).toChar
        n = (n - m) / 26
      }

      res.reverse
    }
  }

  def solve = {
    val n = nextInt
    (1 to n).foreach { x =>
      var s = nextString
      if (isAType(s)) {
        s = s.replace("R", "")
        s = s.replace("C", " ")
        val arr = s.split(" ")
        val row = arr(0)
        val column = arr(1)

        out.println(s"${transform(column)}$row")
      } else {
        val row = s.filter(c => c >= '0' && c <= '9').mkString("")
        val column = s.filter(c => c >= 'A' && c <= 'Z').mkString("")
        out.println(s"R${row}C${transform(column)}")
      }
    }
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }
}

object B1 extends App{
	val r1 = "R([0-9]+)C([0-9]+)".r
	val r2 = "([A-Z]+)([0-9]+)".r
	val chars = ('A' to 'Z').toArray

	def toCR(r: Int, c: Int) = {
		def brk(sc: Int): String = {
			if(sc>0) brk((sc-1)/26) + chars((sc-1) % 26)
			else ""
		}
		brk(c) + r
	}

	def toRC(c: String, r: Int) = {
		val left_foldc = c.foldLeft(0){ (l, c) => (l*26) + (c-'A'+1) }
		s"R${r}C${left_foldc}"
	}

	for(i <- 1 to scala.io.StdIn.readInt()) scala.io.StdIn.readLine() match {
		case r1(r, c) => println(toCR(r.toInt, c.toInt))
		case r2(c, r) => println(toRC(c, r.toInt))
	}

}

object B extends App {
import java.util.{Scanner => Inputer}
import scala.util.matching.Regex

	val in = new Inputer(System.in);
	val n = in nextInt

	val numRep = """R(\d+)C(\d+)""".r
	val letRep = """([A-Z]+)(\d+)""".r

	def letterToNumeral(s: String) = {
	  var res = 0
	  for (c <- s) {
	    res = res * 26 + (c - 'A')
	  }

	  var i = 1
	  var p = 26
	  while (i < s.length) {
	    res += p
	    i += 1
	    p *= 26
	  }
	  res + 1
	}

	def numeralToLetter(x: Int) = {
	  var t = x-1

	  var i = 1
	  var p = 26
	  while (p < t) {
	    i += 1
	    t -= p
	    p *= 26
	  }
	  i -= 1
	  p /= 26

	  var s = ""
	  while (i >= 0) {
	    s = ('A' + t % 26).toChar + s
	    t /= 26
	    i -= 1
	  }

	  s
	}

	var i = 0
	while (i < n) {
	  val s = in.next()
	  s match {
	    case numRep(rstr, cstr) => {
	      val r = rstr toInt
	      val c = cstr toInt;
	      println(numeralToLetter(c) + r)
	    }
	    case letRep(rstr, cstr) => {
	      println("R" + cstr + "C" + letterToNumeral(rstr))
	    }
	  }
	  i += 1
	}
}

import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  def numToStr(num: Int, strlen: Int, x: Int): String =
    if(strlen == 1 && num <= 26) ('A' + num - 1).toChar.formatted("%c")
    else if(num > x * 26) numToStr(num - 26 * x, strlen + 1, x * 26)
    else ('A' + (num - 1) / x).toChar.formatted("%c") + numToStr(1 + (num - 1) % x, strlen - 1, x / 26)
  def numToStr(num: Int): String = numToStr(num, 1, 1)

  def strToNum(str: String) = {
    (1 until str.length).foldLeft((1, 0)) {
      case ((cur, sum), _) => (cur * 26, sum + cur * 26)
    }._2 + str.foldLeft(0) {
      case (sum, char) => sum * 26 + char - 'A'
    } + 1
  }

  def ans = (for(_ <- 1 to readInt) yield {
    val p1 = "R(\\d+)C(\\d+)".r
    val p2 = "([A-Z]+)(\\d+)".r
    reader.readLine() match {
      case p1(row, column) => numToStr(column.toInt) + row
      case p2(row, column) => "R%sC%d".format(column, strToNum(row))
    }
  }).mkString("\n")

  def main(args: Array[String]) {
    println(ans)
  }
}

object Spreadsheets extends App {
  val lines = io.Source.stdin.getLines
  val n = lines.next.toInt

  val rcPattern = """^R(\d+)C(\d+)$""".r
  val letterPattern = """^([A-Z]+)(\d+)$""".r
  val letters = 'A' to 'Z'

  lines.take(n).foreach(coordinates => convert(coordinates))

  def convert(coordinates: String) {
    rcPattern.findFirstMatchIn(coordinates) match {
      case Some(result) => convertRcCoordinates(result.group(1), result.group(2))
      case None => letterPattern.findFirstMatchIn(coordinates) match {
        case Some(result) => convertLetterCoordinates(result.group(2), result.group(1))
        case None =>
      }
    }
  }

  def convertRcCoordinates(row: String, col: String) {
    val colInt = col.toInt

    var resultCol = ""
    var remainder = colInt
    while (remainder > 0) {
      resultCol = (letters((remainder-1) % 26).toString) + resultCol
      remainder = ((remainder-1) / 26)
    }

    println(resultCol + row)
  }

  def convertLetterCoordinates(row: String, col: String) {
    var resultCol = 0
    var remainder = col
    while (!remainder.isEmpty) {
      resultCol = resultCol * 26 + (letters.indexOf(remainder.head) + 1)
      remainder = remainder.tail
    }

    println("R" + row + "C" + resultCol)
  }
}

object Main {
  private val chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

  sealed trait Index {
    def print: Unit
  }

  case class CharIndex(row: Int, col: String) extends Index {
    private def convert(str: String) = str.foldLeft(0) { (a, c) =>
      a * 26 + (c - 'A').toInt + 1
    }

    override def print {
      println("R" + row + "C" + convert(col))
    }
  }

  case class NumberIndex(row: Int, col: Int) extends Index {
    private def divide(num: Int): List[Int] = {
      val div = (num - 1) / 26
      if (div == 0) List((num - 1)% 26)
      else divide(div) ::: List((num - 1) % 26)
    }

    private def convert(num: Int) = divide(num).map(chars(_)).mkString

    override def print {
      println(convert(col) + row)
    }
  }

  val cir = "([A-Z]+)([0-9]+)".r
  val iir = "R([0-9]+)C([0-9]+)".r

  def main(args: Array[String]) {
    val n = readInt()
    for(_ <- 1 to n) {
      readLine match {
        case cir(col, row) => CharIndex(row.toInt, col).print
        case iir(row, col) => NumberIndex(row.toInt, col.toInt).print
      }
    }
  }
}

object Main extends App {
  val n = scala.io.StdIn.readLine().toInt;
  val string_set: Array[String] = (1 to n).map((_) => scala.io.StdIn.readLine()).toArray;
  var next: String = "";

//  var string_set: Array[String] = Array();
//  for (i <- 1 to n)
//    string_set +:= scala.io.StdIn.readLine();

  for (i <- 1 to n) {
//    next = string_set(string_set.length - i);
    next = string_set(i - 1)

    var (l, r) = (-1, next.length);
    while (Character.isAlphabetic(next(l + 1)))
      l += 1;
    while (Character.isDigit(next(r - 1)))
      r -= 1;

    if (r - l == 1)
      print("R" + next.substring(r) + "C" + func.fromTE(next.substring(0, r)) + "\n")
    else
      print(func.toTE(next.substring(r).toInt) + next.substring(l + 1, r - 1) + "\n")
  }
}

object func {
  val alphabet = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                       "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

  def toTE(source: Int): String = {
    var inter = source
    var target = ""
    while (inter > 0) {
      target = alphabet((inter - 1) % 26) + target;
      inter = math.floor((inter - 1) / 26).toInt;
    }
    target
  }

  def fromTE(source: String): Int = source.toSeq.foldLeft(0){
    var i = 0;
    val sLength = source.length;

    (res, symb) => {
      i += 1;
      res + (Char.char2int(symb) - 'A'.toInt + 1) * math.pow(26, sLength - i).toInt }
  }
}

object OneB extends App {

	val n = readInt

	val rcPattern = """R(\d+)C(\d+)""".r
	val otherPattern = """([A-Z]+)(\d+)""".r

	(0 until n) foreach { i =>
		readLine match {
			case rcPattern(row, col) =>
				println(numToLetter(col) + row)
			case otherPattern(col, row) =>
				println("R" + row + "C" + letterToNum(col))
		}

	}

	def letterToNum = { str: String =>
		str.foldLeft(0) { (num, char) =>
			num * 26 + (char - 'A') + 1
		}
	}

	def numToLetter = { nump: String =>

		import scala.collection.mutable.Stack
		val str = new Stack[Char]
		var num = nump.toInt
		while (num > 0) {
			var alpha = (num - 1) % 26
			num = (num - 1) / 26
			str.push(('A' + alpha).toChar)
		}
		str.mkString("")
	}

}

object Main extends App {
  def rctoletter(x : Long) : String = {
    var result : String = ""
    var number = x
    while(number > 0)
    {
      var a = (number-1) % 26
      number = (number-1) / 26
      result = ('A' + a).toChar + result
    }
    result
  }
  def lettertorc(x : String) : Long = {
    var result : Long = 0
    for(c <- x)
      result = (result) * 26 + (c-'A')+1
    result
  }
  val n = readLine().toInt

  val numRegexp = """R(\d+)C(\d+)""".r
  val letRegexp = """([A-Z]+)(\d+)""".r

  for (i <- 1 to n)
  {
    val in : String = readLine()

    in match
    {
      case numRegexp(rnum, cnum) => {
        println(rctoletter(cnum.toLong)+rnum)
      }
      case letRegexp(cstr, rnum) => {
        val cnum = lettertorc(cstr)
        println("R"+rnum+"C"+cnum)
      }
    }
  }
}

object Main extends App {
  val n = scala.io.StdIn.readLine().toInt;
  val string_set: Array[String] = (1 to n).map((_) => scala.io.StdIn.readLine()).toArray;
  var next: String = "";

//  var string_set: Array[String] = Array();
//  for (i <- 1 to n)
//    string_set +:= scala.io.StdIn.readLine();

  for (i <- 1 to n) {
//    next = string_set(string_set.length - i);
    next = string_set(i - 1)

    var (l, r) = (-1, next.length);
    while (Character.isAlphabetic(next(l + 1)))
      l += 1;
    while (Character.isDigit(next(r - 1)))
      r -= 1;
    if (r - l == 1) {
      printf("R%sC%d\n", next.substring(r), func.fromTE(next.substring(0, r)));
    }
    else {
      printf("%s%s\n", func.toTE(next.substring(r).toInt), next.substring(l + 1, r - 1))
    }
  }
}

object func {
  val alphabet = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                       "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

  def toTE(source: Int): String = {
    var inter = source
    var target = ""
    while (inter > 0) {
      target = alphabet((inter - 1) % 26) + target;
      inter = math.floor((inter - 1) / 26).toInt;
    }
    target
  }

  def fromTE(source: String): Int = source.toSeq.foldLeft(0){
    var i = 0;
    val sLength = source.length;

    (res, symb) => {
      i += 1;
      res + (Char.char2int(symb) - 'A'.toInt + 1) * math.pow(26, sLength - i).toInt }
  }
}

object spreadsheets extends App {
  val chars = ('A' to 'Z').toArray
  val RC = "R([0-9]+)C([0-9]+)".r
  val CR = "([A-Z]+)([0-9]+)".r

  def toCR(r: Int, c: Int) = {
    def c2s(c: Int): String =
      if(c > 0) c2s((c - 1) / 26) + chars((c - 1) % 26)
      else ""
    c2s(c) + r
  }
  def toRC(c: String, r: Int) = {
    val ci = c.foldLeft(0) { (l, c) => (l * 26) + (c - 'A' + 1) }
    s"R${r}C${ci}"
  }

  for(i <- 1 to readInt) readLine match {
    case RC(r, c) => println(toCR(r.toInt, c.toInt))
    case CR(c, r) => println(toRC(c, r.toInt))
    //case l => println(s"ERROR: $l")
  }
}

import io.Source

object SpreadSheet {
    val numeric = """R(\d+)C(\d+)""".r
    val alphaNumeric = """([A-Z]+)(\d+)""".r

    def main(args: Array[String]) = {
        val lines = Source.stdin.getLines()
        lines.next()
        lines.foreach(processLine _)
    }

    def processLine(line: String) = {
        line match {
            case numeric(row, column) => println(numericToAlphaNumeric(row.toInt, column.toInt))
            case alphaNumeric(column, row) => println(alphanumericToNumeric(row.toInt, column))
        }
    }

    def numericToAlphaNumeric(row: Int, column: Int): String = {
        val newCol = new StringBuilder
        var currCol = column
        var newChar = 'a'

        // if currCol % 26 == 0, then write a 'Z', divide by 26 and subtract by 1
        while (currCol > 0) {
            if (currCol % 26 == 0) {
                newChar = 'Z'
                currCol = currCol / 26 - 1
            }
            else {
                newChar = ('A' + (currCol % 26) - 1).toChar
                currCol = currCol / 26
            }
            newCol += newChar
        }
        return newCol.reverse.toString + row
    }

    def alphanumericToNumeric(row: Int, column: String): String = {
        var offset = 1

        var numericalColumn = 0
        for (ch <- column.reverse) {
            numericalColumn += (ch - 64) * offset
            offset *= 26
        }

        return "R" + row + "C" + numericalColumn
    }

    def printTest(stop: Int) = {
        var prefix = "R1C"
        var arg = ""
        var failed = false
        for (col <- 1 to stop) {
            arg = prefix + col
            var result = numericToAlphaNumeric(1, col)
            val alphaNumeric(stringColumn, _) = result
            if (arg != alphanumericToNumeric(1, stringColumn)) {
                println("We had a booboo: arg was " + arg + ", conversion was: " + result)
                failed = true
            }
        }
        if (!failed) {
            println("All tests passed")
        }
    }
}

import scala.io.StdIn._

object _1B {
  def main (args: Array[String]) = {
    val num = readInt
    val coords = new Array[String](num);
    for (i <- 0 until num) {
      coords(i) = readLine
    }

    for (coord <- coords)
      println(convert(coord))
  }

  def convert (coord: String) = {
    var col = ""
    var row = ""
    if (coord.matches("R[0-9]+C[0-9]+")) {
      val idx = coord.indexWhere { x => x == 'C' }
      row = coord.slice(1, idx)
      col = coord.slice(idx+1, coord.length)
      col = toABC(col)

      col+row
    }
    else {
      val idx = coord.indexWhere { x => x.isDigit }
      col = coord.slice(0, idx)
      row = coord.slice(idx, coord.length)
      col = toDigit(col)

      "R"+row+"C"+col

    }

  }

  def toABC(digit: String) = {
    var d = digit.toInt
    var r = 0
    var abc = ""
    val alphabet = "ZABCDEFGHIJKLMNOPQRSTUVWXY"

    while (d / 26 > 0) {
      r = d % 26
      abc = alphabet.charAt(r) + abc
      d = d / 26
      if (r == 0)
        d -= 1
    }
    if (d > 0)
      abc = alphabet.charAt(d) + abc

    abc
  }

  def toDigit(abc: String) = {
    var d = 0
    var f = 1
    for ( i <- 1 to abc.length) {
      d += (abc.charAt(abc.length-i) - 'A' + 1) * f
      f *= 26
    }
    d.toString
  }
}

import scala.io.StdIn._

object _1B {
  def main (args: Array[String]) = {
    var num = readInt
    var coords = new Array[String](num);
    for (i <- 0 until num) {
      coords(i) = readLine
    }

    for (coord <- coords)
      println(convert(coord))
  }

  def convert (coord: String) = {
    var col = ""
    var row = ""
    if (coord.matches("R[0-9]+C[0-9]+")) {
      var idx = coord.indexWhere { x => x == 'C' }
      row = coord.slice(1, idx)
      col = coord.slice(idx+1, coord.length)
      col = toABC(col)

      col+row
    }
    else {
      var idx = coord.indexWhere { x => x.isDigit }
      col = coord.slice(0, idx)
      row = coord.slice(idx, coord.length)
      col = toDigit(col)

      "R"+row+"C"+col

    }

  }

  def toABC(digit: String) = {
    var d = digit.toInt
    var r = 0
    var abc = ""
    var alphabet = "ZABCDEFGHIJKLMNOPQRSTUVWXY"

    while (d / 26 > 0) {
      r = d % 26
      abc = alphabet.charAt(r) + abc
      d = d / 26
      if (r == 0)
        d -= 1
    }
    if (d > 0)
      abc = alphabet.charAt(d) + abc

    abc
  }

  def toDigit(abc: String) = {
    var d = 0
    var f = 1
    for ( i <- 1 to abc.length) {
      d += (abc.charAt(abc.length-i) - 'A' + 1) * f
      f *= 26
    }
    d.toString
  }
}

import scala.collection.mutable.ListBuffer

object Spreadsheets {

  def main(args: Array[String]) = {
    val n = scala.io.StdIn.readLine().toInt
    for (_ <- 0 until n) {
      val line = scala.io.StdIn.readLine()
      var is_charcters = true
      val values = new ListBuffer[Int]
      var i = 0
      while (i < line.length) {
        var value = 0
        if (is_charcters) {
          while (i < line.length && line(i).isUpper) {
            value = value * 26 + line(i) - 'A' + 1
            i += 1
          }
        } else {
          while (i < line.length && line(i).isDigit) {
            value = value * 10 + line(i) - '0'
            i += 1
          }
        }
        is_charcters = !is_charcters
        values += value
      }
      if (values.length == 4) {
        var (r, c) = (values(1), values(3))
        val col = new StringBuilder
        while (c > 0) {
          col.append( ('A' + ((c + 25) %  26)).toChar  )
          c -= 1
          c /= 26
        }
        val str = col.reverse.toString()
        printf("%s%d\n", str, r)
      } else {
        printf("R%dC%d\n", values.reverse:_*)

      }
    }
  }
}

import java.util.Scanner

object Main{

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    for (i <- 0 until n) {
      val rcPattern = "R(\\d+)C(\\d+)".r
      val namePattern = "([A-Z]+)(\\d+)".r
      sc.next() match {
        case rcPattern(r, c) => println(rc2Name(r.toInt, c.toInt))
        case namePattern(c, r) => println(name2RC(c, r.toInt))
        case _ =>
      }
    }
  }

  def rc2Name(r: Int, c: Int): String = {
    var cTmp = c
    var cName = ""
    do {
      val remainder = cTmp % 26
      if (remainder == 0) {
        cName = 'Z' + cName
        cTmp -= 26
      } else {
        cName = (remainder + 'A'.toInt - 1).toChar.toString() + cName
      }
      cTmp /= 26
    } while (cTmp != 0)
    return cName + r
  }

  def name2RC(c: String, r: Int): String = {
    val length = c.length()
    var cVal = 0
    for (i <- 0 until length) {
      cVal += (c.charAt(i) - 'A'.toInt + 1) * math.pow(26, length - 1 - i).asInstanceOf[Int]
    }
    return "R" + r + "C" + cVal
  }
}

/**
 * Created by gzq on 15-4-4.
 */
object CF1B {
  def letters2Numbers(str: String): Int = {
    str.map(letter => letter - 'A' + 1).reduceLeft((sum, ele) => sum * 26 + ele)
  }

  def numbers2Letters(x: Int): String = {
    var t = x-1

    var i = 1
    var p = 26
    while (p < t) {
      i += 1
      t -= p
      p *= 26
    }
    i -= 1
    p /= 26

    var s = ""
    while (i >= 0) {
      s = ('A' + t % 26).toChar + s
      t /= 26
      i -= 1
    }

    s
  }

  def main(args: Array[String]) {
    val in = scala.io.StdIn
    val count = in.readInt()

    // Define patters
    // pattern1 matches strings like BC23
    // pattern2 matches strings like R23C55
    val pattern1 = """([a-zA-Z]+)(\d+)""".r
    val pattern2 = """R(\d+)C(\d+)""".r

    for (i <- 1 to count) {
      val line = in.readLine()

      line match {
        case pattern1(column, row) => println("R" + row + "C" + letters2Numbers(column))
        case pattern2(row, column) => println(numbers2Letters(column.toInt) + row)
      }
    }
  }
}

import scala.annotation.tailrec
object X extends App {
  val inp = scala.io.StdIn.readLine()
  val lines = inp.toInt

  case class Stand(val row: Int, val col: Int);

  val rowColToStand = (rowCol: String) => {
    val rCRegex = "R(.*)C(.*)".r
    rCRegex.findFirstMatchIn(rowCol) match {
      case None        => Stand(0, 0)
      case Some(value) => Stand(value.group(1).toInt, value.group(2).toInt)
    }
  }

  val standToRowCol = (stand: Stand) => {
    stand match {
      case Stand(row, col) => s"R${row}C${col}"
    }
  }

  val baseToDec = (baseRep: String, baseMap: Map[String, Int]) => {
    val baseSize = baseMap.size - 1

    baseRep.foldLeft(0)((acc, currChar) =>
      (acc + baseMap(currChar.toString())) * baseSize
    ) / baseSize
  }

  @tailrec
  def decToBase(
      num: Int,
      inverseBaseMap: Map[Int, String],
      acc: List[String] = List()
  ): String = {
    val baseSize = inverseBaseMap.size - 1

    if (num == 0) {
      acc.mkString("")
    } else {
      val rem = num % baseSize
      val actualRem = if (rem == 0) baseSize else rem
      val diff = (num - actualRem) / baseSize;
      decToBase(diff, inverseBaseMap, inverseBaseMap(actualRem) +: acc)
    }
  }

  val alphaBase = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .split("")
    .foldLeft(Map[String, Int]())((accMap, currChar) =>
      accMap + (currChar.toString() -> accMap.size)
    )
  val inverseAlphaBase = alphaBase.map(_.swap)

  val alphaToStand = (alphaRep: String) => {
    val alphaRegex = "([A-Z]*)([0-9]*)".r
    alphaRegex.findFirstMatchIn(alphaRep) match {
      case None => Stand(0, 0)
      case Some(value) => {
        Stand(value.group(2).toInt, baseToDec(value.group(1), alphaBase))
      }
    }
  }

  val standToAlpha = (stand: Stand) =>
    s"${decToBase(stand.col, inverseAlphaBase)}${stand.row}"

  val alphaToRowCol = (alpha: String) => standToRowCol(alphaToStand(alpha))
  val rowColToAlpha = (rowCol: String) => standToAlpha(rowColToStand(rowCol))

  (0 until lines).foreach(l => {
    val line = scala.io.StdIn.readLine()
    val rCRegex = "^R[0-9]+C[0-9]+$".r

    val otherRep = rCRegex.findFirstMatchIn(line) match {
      case None        => alphaToRowCol(line)
      case Some(value) => rowColToAlpha(line)
    }
    println(otherRep)

  })
}

import scala.util.matching.Regex

object Main extends App {

  val ground = 'A'.toInt - 1
  val step = 'Z'.toInt - ground

  def letterToDigit(value: String): Int = {
    if (value.length > 1) {
      ((value.charAt(0).toInt - ground) *  Math.pow(step, value.length -1)).toInt + letterToDigit(value.substring(1))
    } else {
      value.charAt(0).toInt - ground
    }
  }

  def digitToLetter(value: Int): String = {
    if (value <= step) {
      (value + ground).toChar.toString
    } else {
      if((value % step) > 0) {
        digitToLetter(value / step) + (value % step + ground).toChar.toString
      } else {
        digitToLetter(value / step -1) + ( step + ground).toChar.toString
      }
    }
  }

  def translate(value: String) = {
    if (value.matches("R\\d{1,}C\\d{1,}")) {
      val cIndex = value.indexOf("C")
      val row = value.substring(1, cIndex)
      val column = value.substring(cIndex + 1).toInt
      digitToLetter(column) + row
    }
    else {
      val pattern = new Regex("[A-Z]*")
      val column = pattern.findFirstIn(value).get
      val row = value.substring(column.size)
      "R" + row + "C" + letterToDigit(column)
    }
  }

  val numOfRounds = Console.readInt
  if (numOfRounds <= 0 || numOfRounds > 1e5f) {
    throw new Exception("Illegal value")
  }

  for (i <- 1 to numOfRounds) {
    println(translate(Console.readLine()))
  }

}

import java.util.Scanner

object Main {
  val alphList = ('A' to 'Z').toList
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val n = sc.nextInt
    for (i <- 1 to n) {
      val str = sc.next
      val p = "R[1-9][0-9]*C[1-9][0-9]*".r
      if (str matches "R[1-9][0-9]*C[1-9][0-9]*") {
        val a = str.split("[RC]")
        println(numToStr(a(2).toInt).reverse + a(1))
      } else {
        println("R" + str.split("[A-Z]+")(1) + "C" + f(str.split("[0-9]+")(0).toList))
      }
    }
  }
  def numToStr(n: Int): String = ((n - 1) / 26, (n - 1) % 26) match {
    case (0, i) => alphList(i).toString
    case (m, i) => alphList(i) + numToStr(m)
  }

  def f(xs: List[Char]): Int = xs match {
    case List() => 0
    case y :: ys => (y - 'A' + 1) * math.pow(26, ys.size).toInt + f(ys)
  }
}

import scala.util.matching.Regex

object SpreadSheet{
  val RowCollumn = new Regex("R[0-9]+C[0-9]+")

  def main(args: Array[String]): Unit = {
    val n = readln.toInt
    (1 to n)
      .iterator
      .map( _ =>
      readln
    ).map( string =>
      if(isRowCollumn(string)){
        rc2classic(string)
      } else {
        classic2rc(string)
      }
    ).foreach(println)
  }

  def isRowCollumn = corresponds2patter(RowCollumn) _

  def rc2classic(s: String): String = {
    val rc = s.drop(1).split("C").map(_.toInt)
    val (row,collumn) = (rc(0),rc(1))
    s"${int2collumn(collumn,"")}$row"
  }

  def classic2rc(s: String):String = {
    val collumn = s.takeWhile(_.isLetter)
    val row = s.dropWhile(_.isLetter).toInt
    s"R${row}C${collumn2int(collumn,0)}"
  }

  def int2collumn(i:Int,s: String):String = i match {
    case 0 => s
    case x =>
      int2collumn((x-1) / 26, s"${(ordOfA + ((x+25) % 26) ).toChar}$s")
  }

  def collumn2int(s:String,i:Int): Int =
    if (s.isEmpty) i else {
      collumn2int(s.drop(1),i*26 + (s.charAt(0).toInt - ordOfA +1))
    }

  def ordOfa = 'a'.toInt
  def ordOfz = 'z'.toInt
  def ordOfA = 'A'.toInt
  def ordOfZ = 'Z'.toInt

  def char2Int(char: Char) = char.toInt
  def int2char(number: Int) = number.toChar

  def readln: String = scala.io.StdIn.readLine()

  def corresponds2patter(pattern: Regex)(string: String): Boolean =
    pattern.findFirstIn(string).nonEmpty
}

object P1B {
    def main(args : Array[String]) {
        val n = readLine.toInt
        for (_ <- 1 to n) {
            val alNum = "([A-Z]+)([0-9]+)".r
            val rc = "R([0-9]+)C([0-9]+)".r
            readLine match {
                case alNum(al, num) => {
                    val c = al map {_ - 'A' + 1} reduce {_ * 26 + _}
                    println("R" + num + "C" + c)
                }
                case rc(r, c) => {
                    val al = new Iterator[Char] {
                        var x = c.toInt
                        def hasNext = x > 0
                        def next = {
                            val xNew = (x - 1) / 26
                            val ret = (x - xNew * 26 - 1 + 'A').toChar
                            x = xNew
                            ret
                        }
                    }.mkString.reverse
                    println(al + r)
                }
            }
        }
    }
}

/**
 * Created by gzq on 15-4-4.
 */
object CF1B {
  def letters2Numbers(str: String): Int = {
    str.map(letter => letter - 'A' + 1).reduceLeft((sum, ele) => sum * 26 + ele)
  }

  def numbers2Letters(strNum: String): String = {
    val aLessOne = 'A' - 1
    var num = strNum.toInt
    var result = ""
    while (num != 0) {
      val remainder = num % 26
      if (remainder != 0) {
        result = (remainder + aLessOne).toChar + result
      } else {
        result = result + 'Z'
      }
      num /= 26
    }
    return result
  }

  def main(args: Array[String]) {
    val in = scala.io.StdIn
    val count = in.readInt()

    // Define patters
    // pattern1 matches strings like BC23
    // pattern2 matches strings like R23C55
    val pattern1 = """([a-zA-Z]+)(\d+)""".r
    val pattern2 = """R(\d+)C(\d+)""".r

    for (i <- 1 to count) {
      val line = in.readLine()

      line match {
        case pattern1(column, row) => println("R" + row + "C" + letters2Numbers(column))
        case pattern2(row, column) => println(numbers2Letters(column) + row)
      }
    }
  }
}

import java.util.Scanner

object Solution {
  def main(args: Array[String]): Unit = {

    val scanner = new Scanner(System.in)
    val n = scanner.nextInt()
    for (i <- 0 until n) {
      val str = scanner.next().toUpperCase
      println({
        if (isNormal(str))
          toReverse(str)
        else
          toNormal(str)
      }.toUpperCase)
    }
  }

  def toReverse(str: String): String = {
    val index = str.indexOf("C")
    toSymbol(str.substring(index + 1)) + str.substring(1, index)
  }

  def toNormal(str: String): String = {
    var columnNumber = ""
    var rowNumber = ""
    for (s <- str)
      if (s.isDigit)
        rowNumber = rowNumber + s
      else
        columnNumber = columnNumber + s

    "R" + rowNumber + "C" + toDec(columnNumber)
  }

  def toSymbol(str: String) = {
    var value = Integer.parseInt(str)
    var result = ""
    while (value > 0) {
      val v = value % 26

      result =
        if (v == 0 && value / 26 == 1) {
          value = 0
          "Z" + result
        } else {
          value = value / 26
          getSymbol(v) + result
        }
    }

    result
  }

  def toDec(str: String): String = {
    var result = 0
    for ((s, i) <- str.reverse.zipWithIndex)
      result = result + getNumber(s) * Math.pow(26, i).toInt

    result.toString
  }

  def getSymbol(number: Int): String = if (number == 0) "A" else (('A' - 1) + number).toChar.toString

  def getNumber(s: Char) = s - ('A' - 1)

  def isNormal(str: String): Boolean = str.matches("^R[\\d]+C[\\d]+$")
}

import java.util.Scanner

/**
  * Created by Artem Konovalov on 9/2/16.
  */
object Solution {
  def main(args: Array[String]): Unit = {

    val scanner = new Scanner(System.in)
    val n = scanner.nextInt()
    for (i <- 0 until n) {
      val str = scanner.next().toUpperCase
      println({
        if (isNormal(str))
          toReverse(str)
        else
          toNormal(str)
      }.toUpperCase)
    }
  }

  def isNormal(str: String): Boolean = str.charAt(0) == 'R' && str.charAt(1).isDigit

  def toNormal(str: String): String = {
    val index = str.indexOf('C')
    val rowNumber = str.substring(1, index)
    val columnNumber = str.substring(index + 1)

    reverseDec(columnNumber) + rowNumber
  }

  def toReverse(str: String): String = {
    var rowNumber = ""
    var columnNumber = ""
    for (s <- str)
      if (s.isDigit)
        rowNumber = rowNumber + s
      else
        columnNumber = columnNumber + s

    "R" + rowNumber + "C" + toDec(columnNumber)
  }

  def toDec(str: String): String = {
    var result = 0
    for ((s, i) <- str.reverse.zipWithIndex)
      result = result + ((s - 'A' + 1) * {
        if (i == 0) 1 else 26 * i
      })

    result.toString
  }

  def reverseDec(str: String): String = {
    var result = ""
    var number = Integer.parseInt(str)
    while (number != 0) {
      result = ('A' + (number % 26) - 1).toChar + result
      number = number / 26
    }
    result
  }
}

import scala.collection.mutable._
import scala.math._
object B extends App {
  def isRXCY(s: String): Boolean = {
    if(s.length < 4) return false
    s.count(_ == 'R') == 1 && s.count(_ == 'C') == 1 && s(1).isDigit
  }
  def toExcel(s: String): String = {
    val r = s.slice(s.indexOf('R')+1, s.indexOf('C')).toInt
    val c = s.drop(s.indexOf('C')+1).toInt
    def toAlph(v: Int): String = {
      if(v == 0) return ""
      toAlph((v-1) / 26 + (if(v % 26 == 0) 1 else 0)) + ('A' + (v-1) % 26).toChar
    }
    toAlph(c) + r
  }
  def toRXCY(s: String): String = {
    def toI(s: String, i: Int): Int = {
      if(s.length == 0) return 0
      ((s.last - 'A' + 1) * i) + toI(s.dropRight(1), i * 26)
    }
    val R = """([A-Z]*)([0-9]*)""".r
    s match {
      case R(c,r) =>
        "R" + r + "C" + toI(c,1)
      case _ => null
    }
  }
  val n = readLine.toInt
  for(i <- 0 until n) {
    val s = readLine
    println(
      if(isRXCY(s)) toExcel(s)
      else          toRXCY(s)
    )
  }
}

import scala.collection.mutable._
import scala.math._
object B extends App {
  def isRXCY(s: String): Boolean = {
    if(s.length < 4) return false
    s.count(_ == 'R') == 1 && s.count(_ == 'C') == 1 && s(1).isDigit
  }
  def toExcel(s: String): String = {
    val r = s.slice(s.indexOf('R')+1, s.indexOf('C')).toInt
    val c = s.drop(s.indexOf('C')+1).toInt
    def toAlph(v: Int): String = {
      if(v == 0) return ""
      toAlph(v / 26) + ('A' + (v % 26) - 1).toChar
    }
    def removeAtmark(s: String): String = {
      if(!s.contains("@")) return s
      if(s.startsWith("@")) return removeAtmark(s.tail)
      val Ra = """(.*)(.)@(.*)""".r
      val t = s match {
        case Ra(a,b,c) =>
          a + (b(0)-1).toChar + 'Z' + c
      }
      removeAtmark(t)
    }
    removeAtmark(toAlph(c)) + r
  }
  def toRXCY(s: String): String = {
    def toI(s: String, i: Int): Int = {
      if(s.length == 0) return 0
      ((s.last - 'A' + 1) * i) + toI(s.dropRight(1), i * 26)
    }
    val R = """([A-Z]*)([0-9]*)""".r
    s match {
      case R(c,r) =>
        "R" + r + "C" + toI(c,1)
      case _ => null
    }
  }
  val n = readLine.toInt
  for(i <- 0 until n) {
    val s = readLine
    println(
      if(isRXCY(s)) toExcel(s)
      else          toRXCY(s)
    )
  }
}

import scala.collection.mutable._
import scala.math._
object B extends App {
  def isRXCY(s: String): Boolean = {
    if(s.length < 4) return false
    s.count(_ == 'R') == 1 && s.count(_ == 'C') == 1 && s(1).isDigit
  }
  def toExcel(s: String): String = {
    val r = s.slice(s.indexOf('R')+1, s.indexOf('C')).toInt
    val c = s.drop(s.indexOf('C')+1).toInt
    def toAlph(v: Int): String = {
      if(v == 0) return ""
      toAlph(v / 26) + ('A' + (v % 26) - 1).toChar
    }
    toAlph(c) + r
  }
  def toRXCY(s: String): String = {
    def toI(s: String, i: Int): Int = {
      if(s.length == 0) return 0
      ((s.last - 'A' + 1) * i) + toI(s.dropRight(1), i * 26)
    }
    val R = """([A-Z]*)([0-9]*)""".r
    s match {
      case R(c,r) =>
        "R" + r + "C" + toI(c,1)
      case _ => null
    }
  }
  val n = readLine.toInt
  for(i <- 0 until n) {
    val s = readLine
    println(
      if(isRXCY(s)) toExcel(s)
      else          toRXCY(s)
    )
  }
}

import java.util.Scanner

object B {
  def RC2Normal(r: String, c_str: String): String = {
    val c = c_str.toInt
    val (left, len) = Iterator.iterate((c, 1, 26)){p =>
        val (c_left, count, step) = p
        (c_left - step, count + 1, step * 26)
      }.find(p => p._1 > 0) match {
      case Some(x) => (x._1, x._2)
      }
    val c_converted = ((left - 1, "") /:(1 to len)){(p, i) =>
      (p._1 / 26, ('A'.toInt + (p._1 % 26)).toChar + p._2)}._2
    "%s%s".format(c_converted, r)
  }

  def Normal2RC(c_str: String, r:String): String = {
    val base = (1 to c_str.length).foldLeft(0)((a, b)=>a * 26 + 1)
    val diff = (0 /: c_str) ((s, c)=>s * 26 + c.toInt - 'A'.toInt)
    val c = base + diff
    "R%sC%d".format(r, c)
  }

  def conv(line: String): String = {
    val p_rc = """^R(\d+)C(\d+)$""".r
    val p_norm = """^([A-Z]+)(\d+)$""".r
    return p_rc findFirstIn line match {
      case Some(p_rc(r, c)) => RC2Normal(r, c)
      case None => p_norm findFirstIn line match {
        case Some(p_norm(c, r)) => Normal2RC(c, r)
	case None => "Error"
      }
    }
  }

  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val count = sc.nextInt
    sc.nextLine // skip newline
    for (i <- 1 to count) {
      val line = sc.nextLine
      println(conv(line))
    }
  }
}

import java.util.Scanner

object B {
  def RC2Normal(r: String, c_str: String): String = {
    val c = c_str.toInt
    val (left, len) = Iterator.iterate((c, 1, 1)){p =>
        val (c_left, count, step) = p
        (c_left - step * 26, count + 1, step * 26)
      }.find(p => p._1 < 0) match {
        case Some(x) => (x._1 + x._3, x._2 - 1)
	case None => (-1, -2)
      }
    val c_converted = ((left - 1, "") /:(1 to len)){(p, i) =>
      (p._1 / 26, ('A'.toInt + (p._1 % 26)).toChar + p._2)}._2
    "%s%s".format(c_converted, r)
  }

  def Normal2RC(c_str: String, r:String): String = {
    val base = (1 to c_str.length).foldLeft(0)((a, b)=>a * 26 + 1)
    val diff = (0 /: c_str) ((s, c)=>s * 26 + c.toInt - 'A'.toInt)
    val c = base + diff
    "R%sC%d".format(r, c)
  }

  def conv(line: String): String = {
    val p_rc = """^R(\d+)C(\d+)$""".r
    val p_norm = """^([A-Z]+)(\d+)$""".r
    return p_rc findFirstIn line match {
      case Some(p_rc(r, c)) => RC2Normal(r, c)
      case None => p_norm findFirstIn line match {
        case Some(p_norm(c, r)) => Normal2RC(c, r)
	case None => "Error"
      }
    }
  }

  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val count = sc.nextInt
    sc.nextLine // skip newline
    for (i <- 1 to count) {
      val line = sc.nextLine
      println(conv(line))
    }
  }
}

object Solution extends App {
  val f = "^R(\\d+)C(\\d+)$".r
  val s = "^([A-Z]+)(\\d+)$".r

  def strToVal(n: String): Int = n.foldLeft(0){
      case (acc, el) => acc * 26 + (el - 'A' + 1)
    }

  def valToStr(n: Int): String = n match {
    case 0 => ""
    case t => valToStr(t / 26) + ('A' + t % 26 - 1).toChar
  }

  def strToInt(n: String): String = n match {
    case f(row, column) =>
//      println("Row " + row + " column " + column)
//      (row.toInt, column.toInt)
      s"${valToStr(column.toInt)}$row"
    case s(column, row) =>
//      (strToVal(row), column.toInt)
      s"R${row}C${strToVal(column)}"
  }

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println(Range(0, n).map(_ => strToInt(in.next())).mkString("\n"))
//  println(min + " " + max)
}

object Solution extends App {
  val f = "^R(\\d+)C(\\d+)$".r
  val s = "^([A-Z]+)(\\d+)$".r

  def strToVal(n: String): Int = n.foldLeft(0){
    case (acc, el) => acc * 26 + (el - 'A' + 1)
  }

  def valToStr1(n: Int): String = {
    if (n == 0) {
      ""
    } else {
      valToStr1(n / 27) + (n % 27 + 'A').toChar
    }
  }

  def valToStr(n: Int) = if (n == 1) "A" else valToStr1(n - 1)

  def strToInt(n: String): String = n match {
    case f(row, column) =>
      //      println("Row " + row + " column " + column)
      //      (row.toInt, column.toInt)
      s"${valToStr(column.toInt)}$row"
    case s(column, row) =>
      //      (strToVal(row), column.toInt)
      s"R${row}C${strToVal(column)}"
  }

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  //  println(strToInt("RZ228"))
  //  println(strToInt("RI228"))
  //  println(strToInt("R228C494"))
  //  println(valToStr(1))
  //  println(valToStr(26))
  //  println(valToStr(27))
  //  println(valToStr(28))
  //  Range(1, 1000).foreach(i => println(valToStr(i)))
  println(Range(0, n).map(_ => strToInt(in.next())).mkString("\n"))
  //  println(min + " " + max)
}

object cf1B {
	import java.util.Scanner
	val sc = new Scanner(System.in)
	def main(args : Array[String]) : Unit = {
		val n = sc.nextInt
//		println(rechange("BA23"))
//		println(change("R23C55"))
		for(i <- 1 to n){
			val st = sc.next
			if(st.startsWith("R"))
				println(change(st))
			else
				println(rechange(st))
		}
	}
	def change(st:String):String = {
		val (s1,s2) = (st drop 1 ) span (_.isDigit)
		var num = 0
		s2 drop 1 foreach(c => (num*=10,num+=c.toInt-'0'))
		var s=""
		while(num>=0){
			val mod = num%26
			num/=26
			s+=('A'-1 + ( if(mod==0) {num-=1;26} else mod)).toChar
		}
		s.reverse+s1
	}
	def rechange(st:String):String = {
		val (s1,s2) = st.span(c => c.isLetter)
		var sum = 0
		s1 foreach (c =>(sum*=26,sum=sum+(c.toInt-'A'.toInt+1)))
		"R"+s2+"C"+sum
	}

}

object cf1B {
	import java.util.Scanner
	val sc = new Scanner(System.in)
	def main(args : Array[String]) : Unit = {
		val n = sc.nextInt
//		println(rechange("BA23"))
//		println(change("R23C55"))
		for(i <- 1 to n){
			val st = sc.next
			if(st(0)=='R' && st(1).isDigit)
				println(change(st))
			else
				println(rechange(st))
		}
	}
	def change(st:String):String = {
		val (s1,s2) = (st drop 1 ) span (_.isDigit)
		var num = 0
		s2 drop 1 foreach(c => (num*=10,num+=c.toInt-'0'))
		var s=""
		while(num>0){
			val mod = num%26
			num/=26
			s+=('A'-1 + ( if(mod==0) {num-=1;26} else mod)).toChar
		}
		s.reverse+s1
	}
	def rechange(st:String):String = {
		val (s1,s2) = st.span(c => c.isLetter)
		var sum = 0
		s1 foreach (c =>(sum*=26,sum=sum+(c.toInt-'A'.toInt+1)))
		"R"+s2+"C"+sum
	}

}

object cf1B {
	import java.util.Scanner
	val sc = new Scanner(System.in)
	def main(args : Array[String]) : Unit = {
		val n = sc.nextInt
//		println(rechange("BA23"))
//		println(change("R23C55"))
		for(i <- 1 to n){
			val st = sc.next
			if(st.startsWith("R"))
				println(change(st))
			else
				println(rechange(st))
		}
	}
	def change(st:String):String = {
		val (s1,s2) = (st drop 1 ) span (_.isDigit)
		var num = 0
		s2 drop 1 foreach(c => (num*=10,num+=c.toInt-'0'))
		var s=""
		while(num!=0){
			var head =num%26
			s=s+('A'+head-1).toChar
			num/=26
		}
		s.reverse+s1
	}
	def rechange(st:String):String = {
		val (s1,s2) = st.span(c => c.isLetter)
		var sum = 0
		s1 foreach (c =>(sum*=26,sum=sum+(c.toInt-'A'.toInt+1)))
		"R"+s2+"C"+sum
	}

}

object cf1B {
	import java.util.Scanner
	val sc = new Scanner(System.in)
	def main(args : Array[String]) : Unit = {
		val n = sc.nextInt
//		println(rechange("BA23"))
//		println(change("R23C55"))
		for(i <- 1 to n){
			val st = sc.next
			if(st.startsWith("R"))
				println(change(st))
			else
				println(rechange(st))
		}
	}
	def change(st:String):String = {
		val (s1,s2) = (st drop 1 ) span (_.isDigit)
		var num = 0
		s2 drop 1 foreach(c => (num*=10,num+=c.toInt-'0'))
		var s=""
		while(num>0){
			val mod = num%26
			num/=26
			s+=('A'-1 + ( if(mod==0) {num-=1;26} else mod)).toChar
		}
		s.reverse+s1
	}
	def rechange(st:String):String = {
		val (s1,s2) = st.span(c => c.isLetter)
		var sum = 0
		s1 foreach (c =>(sum*=26,sum=sum+(c.toInt-'A'.toInt+1)))
		"R"+s2+"C"+sum
	}

}

object B1 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def baseAlphatoInt(a: String): Long = {
    var res = 0L
    for(i <- 0 until a.length) {
      res *= 26
      res += a(i)-'A'+1
    }
    res
  }
  def baseIntToAlpha(a: Int): String = {
    var num = a
    var res = ""
    while(num > 0) {
      res = (num%26 + 'A' - 1).toChar + res
      num /= 26
    }
    res
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val reg1 = """R(\d+)C(\d+)""".r
    val reg2 = """([A-Z]+)(\d+)""".r

    for(_ <- 0 until n) {
      val input = read
      val ret = reg1.findFirstMatchIn(input) match {
        case Some(m) =>
          s"${baseIntToAlpha(m.group(2).toInt)}${m.group(1)}"
        case None =>
          reg2.findFirstMatchIn(input) match {
            case Some(m) =>
              s"R${m.group(2)}C${baseAlphatoInt(m.group(1))}"
            case None =>
              "parsing failed"
          }
      }
      println(ret)
    }
  }
}

import java.util.Scanner
import scala.collection.mutable.ListBuffer
object ETables extends App {

  val scanner = new Scanner(System.in)
  val lb = new ListBuffer[String]

  val asciiOffset = 64 // A-1
  val base = 26

  while (scanner.hasNextLine) lb.append(scanner.nextLine().toUpperCase)
  val input = lb.toList.tail

  def basePower(i: Int): Int = {
    def helper(p: Int, acc: Int): Int = {
      if (p == 0) 1 * acc
      else helper(p-1, acc*base)
    }
    helper(i, 1)
  }

  def transform2Number(col: String): Int = {
    def helper(c: String, iter: Int, acc: Int): Int =
      if (c.isEmpty) acc
      else helper(c.substring(1), iter+1, acc + (c.charAt(0) - asciiOffset) * basePower(iter))
    helper(col.reverse, 0, 0)
  }

  def transform2String(col: Int): String = {
    def mod2Char(m: Int): Char = if (m == 0) (asciiOffset+base).toChar else (asciiOffset + m).toChar
    def helper(c: Int, acc: String): String = {
      if (c == 0) acc
      else if (c % base == 0) helper(c / base - 1, acc + mod2Char(0))
      else helper(c / base, acc + mod2Char(c%base))
    }
    helper(col,"").reverse
  }

  def transform(s: String): String = {
    if (s matches """^R\d+C\d+$""") transform2String(s.substring(s.indexOf('C')+1).toInt) + s.substring(1, s.indexOf('C'))
    else "R" + """\d+""".r.findFirstMatchIn("BC23").get + "C" + transform2Number("""^\D+""".r.findFirstMatchIn("BC23").get.toString())
  }

  input.foreach(s => println(transform(s)))
}

import java.util.Scanner
import scala.collection.mutable.ListBuffer
object ETables extends App {

  val scanner = new Scanner(System.in)
  val lb = new ListBuffer[String]

  val asciiOffset = 64 // A-1
  val base = 26

  while (scanner.hasNextLine) lb.append(scanner.nextLine().toUpperCase)
  val input = lb.toList.tail

  def basePower(i: Int): Int = {
    def helper(p: Int, acc: Int): Int = {
      if (p == 0) 1 * acc
      else helper(p-1, acc*base)
    }
    helper(i, 1)
  }

  def transform2Number(col: String): Int = {
    def helper(c: String, iter: Int, acc: Int): Int =
      if (c.isEmpty) acc
      else helper(c.substring(1), iter+1, acc + (c.charAt(0) - asciiOffset) * basePower(iter))
    helper(col.reverse, 0, 0)
  }

  def transform2String(col: Int): String = {
    def mod2Char(m: Int): Char = if (m == 0) (asciiOffset+base).toChar else (asciiOffset + m).toChar
    def helper(c: Int, acc: String): String = {
      if (c == 0) acc
      else if (c % base == 0) helper(c / base - 1, acc + mod2Char(0))
      else helper(c / base, acc + mod2Char(c%base))
    }
    helper(col,"").reverse
  }

  def transform(s: String): String = {
    if (s matches """^R\d+C\d+$""") transform2String(s.substring(s.indexOf('C')+1).toInt) + s.substring(1, s.indexOf('C'))
    else "R" + """\d+""".r.findFirstMatchIn("BC23").get + "C" + transform2Number("""^\D+""".r.findFirstMatchIn("BC23").get.toString())
  }

  input.foreach(transform)
}

/**
 * Created by yangchaozhong on 3/8/15.
 */
object CF1B extends App {
  import java.io.{PrintWriter}
  import java.util.{Scanner}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def isAType(s: String) = {
    s.matches("R\\d+C\\d+")
  }

  def transform(s: String) = {
    if (s.matches("[A-Z]+")) {
      var res = 0
      val rs = s.reverse
      (0 to (rs.length - 1)).foreach { i =>
        res += (rs.charAt(i) - 'A' + 1) * Math.pow(26, i).toInt
      }
      res
    } else {
      var res = ""

      var n = s.toInt
      while (n > 0) {
        var m = n % 26
        if (m == 0) m = 26
        res += (m + 64).toChar
        n = (n - m) / 26
      }

      res.reverse
    }
  }

  def solve = {
    val n = nextInt
    (1 to n).foreach { x =>
      var s = nextString
      if (isAType(s)) {
        s = s.replace("R", "")
        s = s.replace("C", " ")
        val arr = s.split(" ")
        val row = arr(0)
        val column = arr(1)

        out.println(s"${transform(column)}$row")
      } else {
        val row = s.filter(c => c >= '1' && c <= '9').mkString("")
        val column = s.filter(c => c >= 'A' && c <= 'Z').mkString("")
        out.println(s"R${row}C${transform(column)}")
      }
    }
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }
}

object B extends App {
import java.util.{Scanner => Inputer}
import scala.util.matching.Regex

	val in = new Inputer(System.in);
	val n = in nextInt

	val numRep = """R(\d+)C(\d+)""".r
	val letRep = """([A-Z]+)(\d+)""".r

	def letterToNumeral(s: String) = {
	  var res = 0
	  for (c <- s) {
	    res = res * 26 + (c - 'A')
	  }

	  var i = 1
	  var p = 26
	  while (i < s.length) {
	    res += p
	    i += 1
	    p *= 26
	  }
	  res + 1
	}

	def numeralToLetter(x: Int) = {
	  var t = x-1

	  var i = 0
	  var p = 26
	  while (p < t) {
	    i += 1
	    p *= 26
	  }
	  i -= 1
	  p /= 26
	  t -= p

	  var s = ""
	  while (t > 0) {
	    s = ('A' + t % 26).toChar + s
	    t /= 26
	  }

	  s
	}

	var i = 0
	while (i < n) {
	  val s = in.next()
	  s match {
	    case numRep(rstr, cstr) => {
	      val r = rstr toInt
	      val c = cstr toInt;
	      println(numeralToLetter(c) + r)
	    }
	    case letRep(rstr, cstr) => {
	      println("R" + cstr + "C" + letterToNumeral(rstr))
	    }
	  }
	  i += 1
	}
}

object Spreadsheets extends App {
  val lines = io.Source.stdin.getLines
  val n = lines.next.toInt

  val rcPattern = """^R(\d+)C(\d+)$""".r
  val letterPattern = """^([A-Z]+)(\d+)$""".r
  val letters = 'A' to 'Z'

  lines.take(n).foreach(coordinates => convert(coordinates))

  def convert(coordinates: String) {
    rcPattern.findFirstMatchIn(coordinates) match {
      case Some(result) => convertRcCoordinates(result.group(1), result.group(2))
      case None => letterPattern.findFirstMatchIn(coordinates) match {
        case Some(result) => convertLetterCoordinates(result.group(2), result.group(1))
        case None =>
      }
    }
  }

  def convertRcCoordinates(row: String, col: String) {
    val colInt = col.toInt - 1

    var resultCol = ""
    var remainder = colInt
    while (remainder > 0) {
      resultCol = (letters(remainder % 26).toString) + resultCol
      remainder = (remainder / 26) - 1
    }

    println(resultCol + row)
  }

  def convertLetterCoordinates(row: String, col: String) {
    var resultCol = 0
    var remainder = col
    while (!remainder.isEmpty) {
      resultCol = resultCol * 26 + (letters.indexOf(remainder.head) + 1)
      remainder = remainder.tail
    }

    println("R" + row + "C" + resultCol)
  }
}

object Main extends App {
  val n = scala.io.StdIn.readLine().toInt;
  val string_set: Array[String] = (1 to n).map((_) => scala.io.StdIn.readLine()).toArray;
  var next: String = "";

//  var string_set: Array[String] = Array();
//  for (i <- 1 to n)
//    string_set +:= scala.io.StdIn.readLine();

  for (i <- 1 to n) {
//    next = string_set(string_set.length - i);
    next = string_set(i - 1)

    var (l, r) = (-1, next.length);
    while (Character.isAlphabetic(next(l + 1)))
      l += 1;
    while (Character.isDigit(next(r - 1)))
      r -= 1;

    if (r - l == 1)
      print("R", next.substring(r), "C", func.fromTE(next.substring(0, r)), "\n")
    else
      print(func.toTE(next.substring(r).toInt), next.substring(l + 1, r - 1), "\n")
  }
}

object func {
  val alphabet = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                       "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

  def toTE(source: Int): String = {
    var inter = source
    var target = ""
    while (inter > 0) {
      target = alphabet((inter - 1) % 26) + target;
      inter = math.floor((inter - 1) / 26).toInt;
    }
    target
  }

  def fromTE(source: String): Int = source.toSeq.foldLeft(0){
    var i = 0;
    val sLength = source.length;

    (res, symb) => {
      i += 1;
      res + (Char.char2int(symb) - 'A'.toInt + 1) * math.pow(26, sLength - i).toInt }
  }
}

object Main extends App {
  val n = scala.io.StdIn.readLine().toInt;
//  val string_set: Array[String] = (1 to n).map((_) => scala.io.StdIn.readLine()).toArray;
  var next: String = "";

  var string_set: Array[String] = Array();
  for (i <- 1 to n)
    string_set +:= scala.io.StdIn.readLine();

  for (i <- 1 to n) {
    next = string_set(i - 1);
    var (l, r) = (-1, next.length);
    while (Character.isAlphabetic(next(l + 1)))
      l += 1;
    while (Character.isDigit(next(r - 1)))
      r -= 1;
    if (r - l == 1) {
      printf("R%sC%d\n", next.substring(r), func.fromTE(next.substring(0, r)));
    }
    else {
      printf("%s%s\n", func.toTE(next.substring(r).toInt), next.substring(l + 1, r - 1))

  }

    }
}
object func {
  val alphabet = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                       "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

  def toTE(source: Int): String = {
    var inter = source
    var target = ""
    while (inter > 0) {
      target = alphabet((inter - 1) % 26) + target;
      inter = math.floor((inter - 1) / 26).toInt;
    }
    target
  }

  def fromTE(source: String): Int = source.toSeq.foldLeft(0){
    var i = 0;
    val sLength = source.length;

    (res, symb) => {
      i += 1;
      res + (Char.char2int(symb) - 'A'.toInt + 1) * math.pow(26, sLength - i).toInt }
  }
}

import scala.io.StdIn._

object _1B {
  def main (args: Array[String]) = {
    var num = readInt
    var coords = new Array[String](num);
    for (i <- 0 until num) {
      coords(i) = readLine
    }

    for (coord <- coords)
      println(convert(coord))
  }

  def convert (coord: String) = {
    var col = ""
    var row = ""
    if (coord.matches("R[1-9]+C[1-9]+")) {
      var idx = coord.indexWhere { x => x == 'C' }
      row = coord.slice(1, idx)
      col = coord.slice(idx+1, coord.length)
      col = toABC(col)

      col+row
    }
    else {
      var idx = coord.indexWhere { x => x.isDigit }
      col = coord.slice(0, idx)
      row = coord.slice(idx, coord.length)
      col = toDigit(col)

      "R"+row+"C"+col

    }

  }

  def toABC(digit: String) = {
    var d = digit.toInt
    var r = 0
    var abc = ""
    var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    while (d / 26 > 0) {
      r = d % 26
      abc = alphabet.charAt(r-1) + abc
      d = d / 26
    }
    abc = alphabet.charAt(d-1) + abc

    abc
  }

  def toDigit(abc: String) = {
    var d = 0
    var f = 1
    for ( i <- 1 to abc.length) {
      d += (abc.charAt(abc.length-i) - 'A' + 1) * f
      f *= 26
    }
    d.toString
  }
}

import scala.io.StdIn._

object _1B {
  def main (args: Array[String]) = {
    var num = readInt
    var coords = new Array[String](num);
    for (i <- 0 until num) {
      coords(i) = readLine
    }

    for (coord <- coords)
      println(convert(coord))
  }

  def convert (coord: String) = {
    var col = ""
    var row = ""
    if (coord.matches("R[0-9]+C[0-9]+")) {
      var idx = coord.indexWhere { x => x == 'C' }
      row = coord.slice(1, idx)
      col = coord.slice(idx+1, coord.length)
      col = toABC(col)

      col+row
    }
    else {
      var idx = coord.indexWhere { x => x.isDigit }
      col = coord.slice(0, idx)
      row = coord.slice(idx, coord.length)
      col = toDigit(col)

      "R"+row+"C"+col

    }

  }

  def toABC(digit: String) = {
    var d = digit.toInt
    var r = 0
    var abc = ""
    var alphabet = "ZABCDEFGHIJKLMNOPQRSTUVWXY"

    while (d / 26 > 0) {
      r = d % 26
      abc = alphabet.charAt(r) + abc
      d = d / 26
    }
    if (r > 0)
      abc = alphabet.charAt(d) + abc

    abc
  }

  def toDigit(abc: String) = {
    var d = 0
    var f = 1
    for ( i <- 1 to abc.length) {
      d += (abc.charAt(abc.length-i) - 'A' + 1) * f
      f *= 26
    }
    d.toString
  }
}

import scala.annotation.tailrec
object X extends App {
  val inp = scala.io.StdIn.readLine()
  val lines = inp.toInt

  case class Stand(val row: Int, val col: Int);

  val rowColToStand = (rowCol: String) => {
    val rCRegex = "R(.*)C(.*)".r
    rCRegex.findFirstMatchIn(rowCol) match {
      case None        => Stand(0, 0)
      case Some(value) => Stand(value.group(1).toInt, value.group(2).toInt)
    }
  }

  val standToRowCol = (stand: Stand) => {
    stand match {
      case Stand(row, col) => s"R${row}C${col}"
    }
  }

  val baseToDec = (baseRep: String, baseMap: Map[String, Int]) => {
    val baseSize = baseMap.size - 1

    baseRep.foldLeft(0)((acc, currChar) =>
      (acc + baseMap(currChar.toString())) * baseSize
    ) / baseSize
  }

  @tailrec
  def decToBase(
      num: Int,
      inverseBaseMap: Map[Int, String],
      acc: List[String] = List()
  ): String = {
    val baseSize = inverseBaseMap.size - 1

    if (num == 0) {
      acc.mkString("")
    } else {
      val rem = num % baseSize
      val actualRem = if (rem == 0) baseSize else rem
      val diff = (num - actualRem) / baseSize;
      decToBase(diff, inverseBaseMap, inverseBaseMap(actualRem) +: acc)
    }
  }

  val alphaBase = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .split("")
    .foldLeft(Map[String, Int]())((accMap, currChar) =>
      accMap + (currChar.toString() -> accMap.size)
    )
  val inverseAlphaBase = alphaBase.map(_.swap)

  val alphaToStand = (alphaRep: String) => {
    val alphaRegex = "([A-Z]*)([0-9]*)".r
    alphaRegex.findFirstMatchIn(alphaRep) match {
      case None => Stand(0, 0)
      case Some(value) => {
        Stand(value.group(2).toInt, baseToDec(value.group(1), alphaBase))
      }
    }
  }

  val standToAlpha = (stand: Stand) =>
    s"${decToBase(stand.col, inverseAlphaBase)}${stand.row}"

  val alphaToRowCol = (alpha: String) => standToRowCol(alphaToStand(alpha))
  val rowColToAlpha = (rowCol: String) => standToAlpha(rowColToStand(rowCol))

  (0 until lines).foreach(l => {
    val line = scala.io.StdIn.readLine()

    try {
      val rCRegex = "^R(.*)C(.*)$".r

      val otherRep = rCRegex.findFirstMatchIn(line) match {
        case None        => alphaToRowCol(line)
        case Some(value) => rowColToAlpha(line)
      }
      println(otherRep)
    } catch {
      case e: Any => println(line)
    }

  })
}

import scala.annotation.tailrec
object X extends App {
  val inp = scala.io.StdIn.readLine()
  val lines = inp.toInt

  case class Stand(val row: Int, val col: Int);

  val rowColToStand = (rowCol: String) => {
    val rCRegex = "R(.*)C(.*)".r
    rCRegex.findFirstMatchIn(rowCol) match {
      case None        => Stand(0, 0)
      case Some(value) => Stand(value.group(1).toInt, value.group(2).toInt)
    }
  }

  val standToRowCol = (stand: Stand) => {
    stand match {
      case Stand(row, col) => s"R${row}C${col}"
    }
  }

  val baseToDec = (baseRep: String, baseMap: Map[String, Int]) => {
    val baseSize = baseMap.size - 1

    baseRep.foldLeft(0)((acc, currChar) =>
      (acc + baseMap(currChar.toString())) * baseSize
    ) / baseSize
  }

  @tailrec
  def decToBase(
      num: Int,
      inverseBaseMap: Map[Int, String],
      acc: List[String] = List()
  ): String = {
    val baseSize = inverseBaseMap.size - 1

    if (num == 0) {
      acc.mkString("")
    } else {
      val rem = num % baseSize
      val actualRem = if (rem == 0) baseSize else rem
      val diff = (num - actualRem) / baseSize;
      decToBase(diff, inverseBaseMap, inverseBaseMap(actualRem) +: acc)
    }
  }

  val alphaBase = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .split("")
    .foldLeft(Map[String, Int]())((accMap, currChar) =>
      accMap + (currChar.toString() -> accMap.size)
    )
  val inverseAlphaBase = alphaBase.map(_.swap)

  val alphaToStand = (alphaRep: String) => {
    val alphaRegex = "([A-Z]*)([0-9]*)".r
    alphaRegex.findFirstMatchIn(alphaRep) match {
      case None => Stand(0, 0)
      case Some(value) => {
        Stand(value.group(2).toInt, baseToDec(value.group(1), alphaBase))
      }
    }
  }

  val standToAlpha = (stand: Stand) =>
    s"${decToBase(stand.col, inverseAlphaBase)}${stand.row}"

  val alphaToRowCol = (alpha: String) => standToRowCol(alphaToStand(alpha))
  val rowColToAlpha = (rowCol: String) => standToAlpha(rowColToStand(rowCol))

  (0 until lines).foreach(l => {
    val line = scala.io.StdIn.readLine()
    try {
      val rCRegex = "^R(.+)C(.+)$".r

      val otherRep = rCRegex.findFirstMatchIn(line) match {
        case None        => alphaToRowCol(line)
        case Some(value) => rowColToAlpha(line)
      }
      println(otherRep)
    } catch {
      case e: Any => println(line)
    }

  })
}

import scala.annotation.tailrec
object X extends App {
  val inp = scala.io.StdIn.readLine()
  val lines = inp.toInt

  case class Stand(val row: Int, val col: Int);

  val rowColToStand = (rowCol: String) => {
    val rCRegex = "R(.*)C(.*)".r
    rCRegex.findFirstMatchIn(rowCol) match {
      case None        => Stand(0, 0)
      case Some(value) => Stand(value.group(1).toInt, value.group(2).toInt)
    }
  }

  val standToRowCol = (stand: Stand) => {
    stand match {
      case Stand(row, col) => s"R${row}C${col}"
    }
  }

  val baseToDec = (baseRep: String, baseMap: Map[String, Int]) => {
    val baseSize = baseMap.size - 1

    baseRep.foldLeft(0)((acc, currChar) =>
      (acc + baseMap(currChar.toString())) * baseSize
    ) / baseSize
  }

  @tailrec
  def decToBase(
      num: Int,
      inverseBaseMap: Map[Int, String],
      acc: List[String] = List()
  ): String = {
    val baseSize = inverseBaseMap.size - 1

    if (num == 0) {
      acc.mkString("")
    } else {
      val rem = num % baseSize
      val actualRem = if (rem == 0) baseSize else rem
      val diff = (num - rem) / baseSize;
      decToBase(diff, inverseBaseMap, inverseBaseMap(actualRem) +: acc)
    }
  }

  val alphaBase = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .split("")
    .foldLeft(Map[String, Int]())((accMap, currChar) =>
      accMap + (currChar.toString() -> accMap.size)
    )
  val inverseAlphaBase = alphaBase.map(_.swap)

  val alphaToStand = (alphaRep: String) => {
    val alphaRegex = "([A-Z]*)([0-9]*)".r
    alphaRegex.findFirstMatchIn(alphaRep) match {
      case None => Stand(0, 0)
      case Some(value) => {
        Stand(value.group(2).toInt, baseToDec(value.group(1), alphaBase))
      }
    }
  }

  val standToAlpha = (stand: Stand) =>
    s"${decToBase(stand.col, inverseAlphaBase)}${stand.row}"

  val alphaToRowCol = (alpha: String) => standToRowCol(alphaToStand(alpha))
  val rowColToAlpha = (rowCol: String) => standToAlpha(rowColToStand(rowCol))

  (0 until lines).foreach(l => {
    try {
      val line = scala.io.StdIn.readLine()

      val rCRegex = "^R(.*)C(.*)$".r

      val otherRep = rCRegex.findFirstMatchIn(line) match {
        case None        => alphaToRowCol(line)
        case Some(value) => rowColToAlpha(line)
      }
      println(otherRep)
    } catch {
      case e: Any =>
    }

  })
}

import scala.annotation.tailrec
object X extends App {
  val inp = scala.io.StdIn.readLine()
  val lines = inp.toInt

  case class Stand(val row: Int, val col: Int);

  val rowColToStand = (rowCol: String) => {
    val rCRegex = "R(.*)C(.*)".r
    rCRegex.findFirstMatchIn(rowCol) match {
      case None        => Stand(0, 0)
      case Some(value) => Stand(value.group(1).toInt, value.group(2).toInt)
    }
  }

  val standToRowCol = (stand: Stand) => {
    stand match {
      case Stand(row, col) => s"R${row}C${col}"
    }
  }

  val baseToDec = (baseRep: String, baseMap: Map[String, Int]) => {
    val baseSize = baseMap.size - 1

    baseRep.foldLeft(0)((acc, currChar) =>
      (acc + baseMap(currChar.toString())) * baseSize
    ) / baseSize
  }

  @tailrec
  def decToBase(
      num: Int,
      inverseBaseMap: Map[Int, String],
      acc: List[String] = List()
  ): String = {
    val baseSize = inverseBaseMap.size - 1

    if (num == 0) {
      acc.mkString("")
    } else {
      val rem = num % baseSize
      val actualRem = if (rem == 0) baseSize else rem
      val diff = (num - actualRem) / baseSize;
      decToBase(diff, inverseBaseMap, inverseBaseMap(actualRem) +: acc)
    }
  }

  val alphaBase = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    .split("")
    .foldLeft(Map[String, Int]())((accMap, currChar) =>
      accMap + (currChar.toString() -> accMap.size)
    )
  val inverseAlphaBase = alphaBase.map(_.swap)

  val alphaToStand = (alphaRep: String) => {
    val alphaRegex = "([A-Z]*)([0-9]*)".r
    alphaRegex.findFirstMatchIn(alphaRep) match {
      case None => Stand(0, 0)
      case Some(value) => {
        Stand(value.group(2).toInt, baseToDec(value.group(1), alphaBase))
      }
    }
  }

  val standToAlpha = (stand: Stand) =>
    s"${decToBase(stand.col, inverseAlphaBase)}${stand.row}"

  val alphaToRowCol = (alpha: String) => standToRowCol(alphaToStand(alpha))
  val rowColToAlpha = (rowCol: String) => standToAlpha(rowColToStand(rowCol))

  (0 until lines).foreach(l => {
    try {
      val line = scala.io.StdIn.readLine()

      val rCRegex = "^R(.*)C(.*)$".r

      val otherRep = rCRegex.findFirstMatchIn(line) match {
        case None        => alphaToRowCol(line)
        case Some(value) => rowColToAlpha(line)
      }
      println(otherRep)
    } catch {
      case e: Any =>
    }

  })
}

import scala.util.matching.Regex

object Main extends App {

  val ground = 'A'.toInt - 1
  val step = 'Z'.toInt - ground

  def letterToDigit(value: String): Int = {
    if (value.length > 1) {
      ((value.charAt(0).toInt - ground) *  Math.pow(step, value.length -1)).toInt + letterToDigit(value.substring(1))
    } else {
      value.charAt(0).toInt - ground
    }
  }

  def digitToLetter(value: Int): String = {
    if (value <= step) {
      (value + ground).toChar.toString
    } else {
      digitToLetter(value / step) + ((value % step) + ground).toChar.toString
    }
  }

  def translate(value: String) = {
    if (value.matches("R\\d{1,}C\\d{1,}")) {
      val cIndex = value.indexOf("C")
      val row = value.substring(1, cIndex)
      val column = value.substring(cIndex + 1).toInt
      digitToLetter(column) + row
    }
    else {
      val pattern = new Regex("[A-Z]*")
      val column = pattern.findFirstIn(value).get
      val row = value.substring(column.size)
      "R" + row + "C" + letterToDigit(column)
    }
  }

  val numOfRounds = Console.readInt
  if (numOfRounds <= 0 || numOfRounds >= 1e5f) {
    throw new Exception("Illegal value")
  }

  for (i <- 1 to numOfRounds) {
    println(translate(Console.readLine()))
  }

}

import scala.util.matching.Regex

object Main extends App {

  val ground = 'A'.toInt - 1
  val step = 'Z'.toInt - ground

  def letterToDigit(value: String): Int = {
    if (value.length > 1) {
      ((value.charAt(0).toInt - ground) * step) + letterToDigit(value.substring(1))
    } else {
      value.charAt(0).toInt - ground
    }
  }

  def digitToLetter(value: Int): String = {
    if (value <= step) {
      (value + ground).toChar.toString
    } else {
      digitToLetter(value / step) + ((value % step) + ground).toChar.toString
    }
  }

  def translate(value: String) = {
    if (value.matches("R\\d{1,}C\\d{1,}")) {
      val cIndex = value.indexOf("C")
      val row = value.substring(1, cIndex)
      val column = value.substring(cIndex + 1).toInt
      digitToLetter(column) + row
    }
    else {
      val pattern = new Regex("[A-Z]*")
      val column = pattern.findFirstIn(value).get
      val row = value.substring(column.size)
      "R" + row + "C" + letterToDigit(column)
    }
  }

  val numOfRounds = Console.readInt
  if (numOfRounds <= 0 || numOfRounds >= 1e5f) {
    throw new Exception("Illegal value")
  }

  for (i <- 1 to numOfRounds) {
    println(translate(Console.readLine()))
  }

}

import scala.util.matching.Regex

object SpreadSheet{
  val RowCollumn = new Regex("R[0-9]+C[0-9]+")

  def main(args: Array[String]): Unit = {
    val n = readln.toInt
    (1 to n)
      .iterator
      .map( _ =>
      readln
    ).map( string =>
      if(isRowCollumn(string)){
        rc2classic(string)
      } else {
        classic2rc(string)
      }
    ).foreach(println)
  }

  def isRowCollumn = corresponds2patter(RowCollumn) _

  def rc2classic(s: String): String = {
    val rc = s.drop(1).split("C").map(_.toInt)
    val (row,collumn) = (rc(0),rc(1))
    s"${int2Collumn(collumn,"")}$row"
  }

  def classic2rc(s: String):String = {
    val collumn = s.takeWhile(_.isLetter)
    val row = s.dropWhile(_.isLetter).toInt
    s"R${row}C${collumn2int(collumn,0)}"
  }

  def int2Collumn(i:Int,s: String):String = i match {
    case 0 => s
    case x =>
      int2Collumn(x / 26, s"${(ordOfA + (x % 26) -1).toChar}$s")
  }

  def collumn2int(s:String,i:Int): Int =
    if (s.isEmpty) i else {
      collumn2int(s.drop(1),i*26 + (s.charAt(0).toInt - ordOfA+1))
    }

  def ordOfa = 'a'.toInt
  def ordOfz = 'z'.toInt
  def ordOfA = 'A'.toInt
  def ordOfZ = 'Z'.toInt

  def char2Int(char: Char) = char.toInt
  def int2char(number: Int) = number.toChar

  def readln: String = scala.io.StdIn.readLine()

  def corresponds2patter(pattern: Regex)(string: String): Boolean =
    pattern.findFirstIn(string).nonEmpty
}

object Main extends App {
  def rctoletter(x : Long) : String = {
    var result : String = ""
    var number = x
    while(number > 0)
    {
      val a = number % 26
      number /= 26
      result = ('A' + a - 1).toChar + result
    }
    result
  }
  def lettertorc(x : String) : Long = {
    var result : Long = 0
    for(c <- x)
      result = (result) * 26 + (c-'A')+1
    result
  }
  val n = readLine().toInt

  val numRegexp = """R(\d+)C(\d+)""".r
  val letRegexp = """([A-Z]+)(\d+)""".r

  for (i <- 1 to n)
  {
    val in : String = readLine()

    in match
    {
      case numRegexp(rnum, cnum) => {
        println(rctoletter(cnum.toLong)+rnum)
      }
      case letRegexp(cstr, rnum) => {
        val cnum = lettertorc(cstr)
        println("R"+rnum+"C"+cnum)
      }
    }
  }
}

import scala.collection.mutable.ListBuffer

object Spreadsheets {

  def main(args: Array[String]) = {
    val n = scala.io.StdIn.readLine().toInt
    for (_ <- 0 until n) {
      val line = scala.io.StdIn.readLine()
      var is_charcters = true
      val values = new ListBuffer[Int]
      var i = 0
      while (i < line.length) {
        var value = 0
        if (is_charcters) {
          while (i < line.length && line(i).isUpper) {
            value = value * 26 + line(i) - 'A' + 1
            i += 1
          }
        } else {
          while (i < line.length && line(i).isDigit) {
            value = value * 10 + line(i) - '0'
            i += 1
          }
        }
        is_charcters = !is_charcters
        values += value
      }
      if (values.length == 4) {
        var (r, c) = (values(1), values(3))
        val col = new StringBuilder
        while (c > 0) {
          col.append( ('A' + ((c + 25) %  26)).toChar  )
          c /= 26
        }
        val str = col.reverse.toString()
        printf("%s%d\n", str, r)
      } else {
        printf("R%dC%d\n", values.reverse:_*)

      }
    }
  }
}

import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    for (i <- 0 until n) {
      val rcPattern = "R(\\d+)C(\\d+)".r
      val namePattern = "([A-Z]+)(\\d+)".r
      sc.next() match {
        case rcPattern(r, c) => println(rc2Name(r.toInt, c.toInt))
        case namePattern(c, r) => println(name2RC(c, r.toInt))
        case _ =>
      }
    }
  }

  def rc2Name(r: Int, c: Int): String = {
    var cTmp = c
    var cName = ""
    do {
      cName = (cTmp % 26 + 'A'.toInt - 1).toChar.toString() + cName
      cTmp /= 26
    } while(cTmp != 0)
    return cName + r
  }

  def name2RC(c: String, r: Int): String = {
    val length = c.length()
    var cVal = 0
    for (i <- 0 until length) {
      cVal += (c.charAt(i) - 'A'.toInt + 1) * math.pow(26, length - 1 - i).asInstanceOf[Int]
    }
    return "R" + r + "C" + cVal
  }
}

import java.util.Scanner

object Main{

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    for (i <- 0 until n) {
      val rcPattern = "R(\\d+)C(\\d+)".r
      val namePattern = "([A-Z]+)(\\d+)".r
      sc.next() match {
        case rcPattern(r, c) => println(rc2Name(r.toInt, c.toInt))
        case namePattern(c, r) => println(name2RC(c, r.toInt))
        case _ =>
      }
    }
  }

  def rc2Name(r: Int, c: Int): String = {
    var cTmp = c
    var cName = ""
    do {
      val remainder = cTmp % 26
      if (remainder == 0) {
        cName = 'Z' + cName
      } else {
        cName = (remainder + 'A'.toInt - 1).toChar.toString() + cName
      }
      cTmp /= 26
    } while (cTmp != 0)
    return cName + r
  }

  def name2RC(c: String, r: Int): String = {
    val length = c.length()
    var cVal = 0
    for (i <- 0 until length) {
      cVal += (c.charAt(i) - 'A'.toInt + 1) * math.pow(26, length - 1 - i).asInstanceOf[Int]
    }
    return "R" + r + "C" + cVal
  }
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val Array(x, y) = in.next().split(" ").map(_.toInt)
  val res = (2 to n).foldLeft((x, x, y, y)) {
    case((xmax, xmin, ymax, ymin), _) =>
      val Array(x, y) = in.next().split(" ").map(_.toInt)
      (Math.max(xmax, x), Math.min(xmin, x), Math.max(ymax, y), Math.min(ymin, y))
   }
  val a = Math.max(res._1 - res._2, res._3 - res._4).toLong
  println(a * a)
}

import java.util._
import java.io._
import java.util

object B {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

  def nextLong: Long = {
    return java.lang.Long.parseLong(next)
  }

  def solve: Int = {
    val n = nextInt
    var minX = Int.MaxValue
    var minY = Int.MaxValue
    var maxX = Int.MinValue
    var maxY = Int.MinValue
    for (i <- 0 until n) {
      val x = nextInt
      minX = Math.min(minX, x)
      maxX = Math.max(maxX, x)
      val y = nextInt
      minY = Math.min(minY, y)
      maxY = Math.max(maxY, y)
    }
    var sq1: Long = Math.abs(minX - maxX).toLong
    sq1 *= sq1;
    var sq2: Long = Math.abs(minY - maxY).toLong
    sq2 *= sq2
    out.println(Math.max(sq1, sq2))

    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}