In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

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

n = gets.to_i

n.times do
	expression = gets
	if expression.match /R(\d+)C(\d+)/
		result = ""
		column = $2.to_i
		until column == 0
			mod = column % 26
			if mod == 0
				mod = 26
				column -= mod
			end

			result << (mod + 64).chr
			column /= 26
		end
		puts result.reverse + $1
	else
		expression.match /([A-Z]+)(\d+)/
		column = 0
		$1.each_byte { |chr| column = column * 26 + chr - 64 }
		puts "R" + $2 + "C" + column.to_s
	end
end

num = gets()

def is_excel_format(name)
  !!(name.match /^[A-Z]+[0-9]+$/)
end

def to_excell(rowcol)
  rowcol =~ /R(\d+)C(\d+)/
  to_letters($2.to_i) + $1
end

def to_rowcol(excell)
  excell =~ /([A-Z]+)(\d+)/
  "R" + $2 + "C" + to_nums($1).to_s
end

def to_letters(num, base=26)
  answer = []
  while num > 0
    mod = (num -1) % 26
    answer.push mod
    num = (num - mod) / base
  end
  answer.reverse.map{|x| (x+65).chr }.join
end

def to_nums(letters)
  letters.reverse.split('').map.with_index{|x, i|
    (x.ord - 65 + 1) * 26 ** i   # convert from letter to number, base 26
  }.reduce{|a,b| a+b}
end

num.to_i.times do |index|
  line = gets()
  if is_excel_format(line)
    puts to_rowcol(line)
  else
    puts to_excell(line)
  end
end

def solve(input)
  if (/R\d+C\d+/ =~ input) == nil
    fromBase26(input)
  else
    toBase26(input)
  end
end

def fromBase26(input)
  charByte = "A".bytes[0]
  numByte = "1".bytes[0]
  letters = Array.new
  numbers = Array.new

  input.chomp.each_byte do |byte|
    if byte < charByte
      numbers.unshift(byte-(numByte-1))
    else
      letters.unshift(byte-(charByte-1))
    end
  end

  rows = arrayToInt(numbers, 10)
  cols = arrayToInt(letters, 26)
  "R#{rows}C#{cols}"
end

def toBase26(input)
  input[0] = ""
  rows, cols = input.split("C")
  val = cols.to_i
  digits = []
  while val != 0
    digits.unshift((val-1)%26)
    val = (val-1)/26
  end
  cols = ""
  for digit in digits
    val = digit + ("A".bytes[0])
    cols += val.chr
  end
  cols + "#{rows}"
end

def arrayToInt(arr, base)
  curr = 1
  int = 0
  for val in arr
    int += val*curr
    curr *= base
  end
  int
end

n = gets.to_i
ans = Array.new(n, nil)
for i in (0...n)
  ans[i] = solve(gets)
end

for answer in ans
  puts answer
end

ask = gets.to_i
ask.times do
  str = gets
  if str =~ /\D\d+\D\d+/ #R23C55
    rows, columns = str.scan(/\d+/)
    num = columns.to_i
    str = ''
    while num >= 1 do
      rem = num % 26
      str = (rem == 0) ? 'Z' + str : (rem + 64).chr + str
      num /= 26
      num -= 1 if rem == 0
    end
    ans = str + rows
  else #BC23
    columns, rows = str.scan(/\D+|\d+/)
    str = columns.reverse
    num = 0
    (0...str.length).each do |i|
      num += (str[i].ord - 64) * 26**i
    end
    ans = 'R' + rows + 'C' + num.to_s
  end
  puts ans
end

alph = ['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']

n = gets.chomp.to_i

lines = []
n.times {lines << gets.chomp}
lines.each do |l|
    if (l =~ /R\d+C\d+/).nil?
        col = 0
        colstr = l.scan(/[A-Z]+/).first.split("")
        colstr.each_with_index do |ch, index|
            col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))
        end
        row = l.scan(/[0-9]+/).first
        puts "R#{row}C#{col}"
    else
        row = l.scan(/R([0-9]+)/).flatten.first
        col = l.scan(/C([0-9]+)/).flatten.first.to_i
        cols = ""
        delta = 0
        loop do
            remainder = (col % 26)
            col = col / 26
            unless col == 0 and remainder - delta == 0
                cols = alph[remainder - 1 - delta] + cols
            end
            delta = remainder - delta <= 0 ? 1 : 0
            break if col == 0

        end
        puts "#{cols}#{row}"
    end
end

number_of_input=gets.to_i
input_arry=[]
i_a=0

loop do
	break if i_a==number_of_input
	input_arry[i_a]=gets.chomp
	i_a +=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash={}
i_b=0

loop do
	break if i_b==26
	@hash[alph[i_b]]=value[i_b]
	i_b+=1
end

def S1_to_S2 (a1)
	r=a1[0]
	i=1

	loop do
		break if a1[i].to_i !=0
		r =r + a1[i]
		i+=1
	end

	r1=r.length
	r2=a1.length
	c1= a1[0 .. (r1-1)].reverse
	row= a1[ r1 .. r2].to_i
	c=0
	i=0

	loop do
		break if i==c1.length
		c= c + (@hash[c1[i]]*(26**i))
		i+=1
	end

	puts "R#{row}C#{c}"
end

def S2_to_S1 (a1)
	s2=a1.split("").map{|s| s}
	r3=3
	s2.find {|i| r3=s2.index(i)+1 if i=='C'}
	i=s2[r3 .. (s2.length - 1)].join.to_i
	row=s2[1 .. (r3-2)].join.to_i
	str_c=""

	loop do
		i=i-26 if i>25 && i%26==0
		if i%26==0
		str_c = str_c + "Z"
		else
		str_c = str_c + @hash.key(i%26)
		end
		i=i/26
		break if i==0
	end

	str_c=str_c.reverse
	puts "#{str_c}#{row}"
end

i_c =0

loop do
    break if i_c==input_arry.length
	input1=input_arry[i_c]

	if 	input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0)
		S1_to_S2 (input1)
	elsif input1[0]=='R' && input1[1].to_i!=0
		k2=input1.split("")
		k=0
		k2.find{|s| k=1 if s=='C'}
		if k==1
			S2_to_S1(input1)
		else
			S1_to_S2 (input1)
		end
	end

	i_c +=1

end

def toBase26 number
    converted = []
    while (number > 0)
        remainder = (number - 1) % 26
        converted << (remainder + 65).chr
        number = (number - remainder) / 26;
    end
    return converted.join.reverse;
end
def fromBase26 number
    s = 0
    if number.length > 0
        s = number[0].ord - 65 + 1;
        for i in 1..number.length-1
            s *= 26;
            s += (number[i].ord - 65 + 1);
        end
    end
    return s
end
t = gets.to_i
for i in 1..t
    s = gets.chomp
    len = s.length
    format = false
    if s[0] == 'R' && s[1].ord < 65 && len >= 4
        j = 2
        r = s[1].to_i
        while j < len && s[j].ord < 65
            r = r*10 + s[j].to_i
            j += 1
        end
        if j!= len && s[j] == 'C'
            c = s[j + 1].to_i
            j += 2
            while j < len && s[j].ord < 65
                c = c*10 + s[j].to_i
                j += 1
            end
            format = true
        else
            c = r
            r = 'R'
        end
    else
        j = 0
        while s[j].ord >= 65
            j += 1
        end
        r = s[0,j]
        c = s[j].to_i
        j += 1
        while j < len
            c = c*10 + s[j].to_i
            j += 1
        end
    end

    # true RXCX
    # false ABCXXX
    if !format
        puts "R#{c}C#{fromBase26 r}"
    else
        puts "#{toBase26 c}#{r}"
    end
end

def whitespace?(c)
  !" \r\n".index(c).nil?
end
def read_word
  s = ''
  c = ' '
  c = $stdin.getc while whitespace?(c)
  begin
    s << c
    c = $stdin.getc
  end while !whitespace?(c)
  return s
end
def read_int
  read_word.to_i
end
def read_float
  read_word.to_f
end
def read_line
  s = ''
  while s.count("\r\n")==s.length
    s = $stdin.readline
  end
  return s
end

$base = ?A

def to_hex(n)
  res = ""
  while n>0
    res << ((n-1)%26 + $base).chr
    n = (n-1) / 26
  end
  res.reverse
end
def from_hex(s)
  res = 0
  s.each_byte do |b|
    res = res*26 + (b - $base + 1)
  end
  res
end
n = read_int
n.times do
  s = read_line
  if s =~ /R(\d+)C(\d+)/
    x,y = $1,$2.to_i
    puts to_hex(y)+x
  else
    i = 0
    y = ""
    while s[i..i]>='A'
      y << s[i]
      i+=1
    end
    puts "R#{s[i...-1]}C#{from_hex(y)}"
  end
end

letters = %w(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)

gets.to_i.times do
  input = gets.strip
  if input =~ /R(\d)+C/
    codes = input.gsub("R", "").split("C").map(&:to_i)
    ans = ""
    codes[1]
    while codes[1] > 0 do
      ans << letters[(codes[1]%26-1)]
      if codes[1]%26!=0
        codes[1] /= 26
      else
        codes[1] /= 26
        codes[1] -=1
      end
    end

    puts "#{ans.reverse}#{codes[0]}"
  else
    code = input.match(/([A-Z])+/).to_s
    sum = 0
    code.chars.each_with_index do |el, i|
      sum += (1+letters.index(el)) * (26**(code.size-i-1))
    end
    puts "R#{input.match(/([0-9])+/)}C#{sum}"
  end
end

def to_spread_number(number)
  spread = ''
  while number > 0
    rem = number % 26
    number /= 26
    if rem == 0
      rem = 26
      number -= 1
    end
    spread = (rem + 64).chr + spread
  end
  spread
end

def to_number(spread_num)
  num, m = 0, 1
  spread_num.reverse.each_char { |c|
    num += (c.ord - 64) * m
    m *= 26
  }
  num
end

for _ in 1..Integer(gets.chomp)
  cell = gets.chomp
  coords = cell.scan(/R(\d+)C(\d+)/).first
  if coords
    puts to_spread_number(coords[1].to_i) + coords[0]
  else
    cell.scan(/([A-Z]+)(\d+)/) { puts "R#{$2}C#{to_number($1)}" }
  end
end

def to_digits(s)
	res = 0
	s.each_byte { |a|
        	res = res * 26 + a - 'A'[0].ord + 1
	}
	res
end

def to_letters(n)
	s = ''
	while n > 0 do
        	r = n % 26
        	if r == 0
        		ad = 'Z'
		else
			ad = ('A'[0].ord + r - 1).chr
		end
        	n = (n - 1) / 26
        	s = s + ad
	end
	s.reverse
end

n = gets.to_i
n.times do
	s = gets
	if /^(\D+)(\d+)$/i =~ s
		m = Regexp.last_match
		puts "R#{m[2]}C#{to_digits(m[1])}"
        elsif /^R(\d+)C(\d+)$/i =~ s
        	m = Regexp.last_match
        	puts "#{to_letters(m[2].to_i)}#{m[1]}"
	end
end

# $stdin = File.open('in')
n = gets.to_i

def conv(num)
	res = ''
	while num > 0
		if num % 26 == 0
			res.concat('Z')
			num -= 1
		else
			res.concat((num % 26 + 65 - 1).chr)
		end
		num /= 26
	end
	res.reverse!
end

for i in 0...n
	s = gets
	m = /R(\d+)C(\d+)/.match(s)
	if m != nil
		num = m[2].to_i
		puts "#{conv(num)}#{m[1]}"
	else
		m = /([A-Z]+)(\d+)/.match(s)
		column = m[1]
		column.reverse!
		cnt, base = 0, 1
		column.length.times do |i|
			cnt += (column[i].ord - 'A'.ord + 1) * base
			base *= 26
		end
		puts "R#{m[2]}C#{cnt}"
	end
end

gets
while i = gets do
	if i =~ /^([A-Z]+)(\d+)$/
		c = 0
		$1.each_byte {|chr| c =  c * 26 + chr - 64}
		print "R", $2, "C", c, "\n"
	elsif i =~ /^R(\d+)C(\d+)/
		c = $2.to_i
		str=""
		while c != 0
			mod = c % 26
			if mod == 0 then
				mod = 26
				c -= mod
			end
			str << (mod + 64).chr
			c /= 26
		end
		print str.reverse, $1, "\n"
	end
end

gets; while i = gets do
	if i =~ /^([A-Z]+)(\d+)$/
		c = 0
		$1.each_byte {|chr| c =  c * 26 + chr - 64}
		print "R", $2, "C", c, "\n"
	elsif i =~ /^R(\d+)C(\d+)/
		c = $2.to_i
		str=""
		while c != 0
			mod = c % 26
			if mod == 0 then
				mod = 26
				c -= mod
			end
			str << (mod + 64).chr
			c /= 26
		end
		print str.reverse, $1, "\n"
	end
end

def is_num(ch)
        return ((ch >= "0") and (ch <= "9")) ? true : false
end
def is_pattern2(str)
        len = str.length()
        return false if str[0]!="R"
        return false if not(is_num(str[1]))
        for i in (2..len-1)
                return true if str[i]=="C"
        end

        false
end

num_line = gets.to_i()
num_line.times {
        str = gets().chomp()
        len = str.length()
        if is_pattern2(str)

                for i in (2..len-1)
                        if str[i]=="C"
                                        c_index = i
                                        break
                        end
                end

                row = str[1..c_index-1].to_i
                col = str[c_index+1..len-1].to_i

                col_string = []

                loop do
                        col -= 1
                        a= (col%26 + 65).chr
                        col_string.unshift(a)
                        col /= 26
                        break if col <=0
                end
                puts "#{col_string.join('')}#{row}"
        else

                for i in (1..len-1)
                        if is_num(str[i])
                                num_index = i
                                break
                        end
                end
                row = str[num_index..len-1].to_i
                col = 0
                for i in (0..num_index-1)
                        base = 26**i
                        col += base * (str[num_index-1-i].ord-"A".ord+1)
                end
                puts "R#{row}C#{col}"
        end
}

n = gets
n = Integer(n)
while n>0
  string = gets
  m = string.size()
  index = 0
  while ('A'..'Z').include? string[index]
    index += 1
  end
  while !(('A'..'Z').include? string[index])
    index += 1
    if index >= m
        break;
    end
  end
  if index == m
    index = 0
    while ('A'..'Z').include? string[index]
      index+=1
    end
    index -= 1
    c = 0
    count = 1
    til = index
    until index < 0
      c += (string[index].unpack("c")[0] - 'A'.unpack("c")[0] + 1) * count
      index -= 1
      count *= 26
    end
    puts "R#{string[til+1..m].chomp}C#{c}"
  else
    index = string.index("C")
    count = Integer(string[index+1..m-2].chomp)
    k = ""
    while count > 0
        while count % 26 == 0 && count > 0
          k = "Z" + k
          count /= 26
          count -= 1
        end
        if count>0
          k = (count % 26 + 64).chr + k
          count /= 26
        end
    end
    puts "#{k}#{string[1..index-1]}"
  end
  n-=1
end

#!/usr/bin/env ruby

def convert(str)
  if str =~ /^R(\d+)C(\d+)$/
    rows, cols  = $1.to_i, $2.to_i
    a = []
    loop do
      cols -= 1
      a.unshift cols % 26
      cols /= 26
      break if cols == 0
    end
    "#{a.map{|i| (i + 65).chr}.join}#{rows}"
  elsif str =~ /^([A-Z]+)(\d+)$/
    cols = 0
    $1.size.times do |i|
      cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)
    end
    "R#{$2}C#{cols}"
  else
    "invalid arg"
  end
end

n = gets.to_i
lines = []
n.times do
  lines << convert(gets.chomp)
end

lines.each{|s| puts s}

require 'scanf'
n = STDIN.gets.scanf('%d').first
while n>0
  l = STDIN.gets.chop
  row = nil
  col = nil
  /R(?<row>\d+)C(?<col>\d+)/=~l
  unless (row and col)
    /(?<col>[A-Z]+)(?<row>\d+)/=~l
    col_ = 0
    i=0
    col.each_byte do |a|
      pos = col.length - i - 1
      col_+=('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)**pos*(a-'A'.bytes.to_a.first+1)
      i+=1
    end
    row = row.to_i
    puts "R"+row.to_s+"C"+col_.to_s
  else
    col = col.to_i
    col_ = ''
    while col!=0
      temp = col % ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)
       if temp ==0
         temp = ('Z'.bytes.to_a.first-'A'.bytes.to_a.first)
         col-=1
       else
         temp-=1
       end
      col_+=['A'.bytes.to_a.first+temp].pack("U")
      col /= ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)
    end
    col_.reverse!
    puts col_+row
  end
  n-=1
end

def n2s(n)
  s = ""
  while n > 0
    s = ("A".ord + (n - 1) % 26).chr + s
    n = (n - (n - 1) % 26 - 1) / 26
  end
  return s
end

def s2n(s)
  n = 0
  s.size.times do |i|
    n *= 26
    n += s[i].ord - "A".ord + 1
  end
  return n
end

n = gets.to_i
n.times do
  str = gets
  if str =~ /^([A-Z]+)(\d+)$/
    c_s = $1
    r = $2.to_i
    c = s2n(c_s)
    puts "R#{r}C#{c}"
  elsif str =~ /^R(\d+)C(\d+)$/
    r = $1.to_i
    c = $2.to_i
    c_s = n2s(c)
    puts "#{c_s}#{r}"
  end
end

def num_to_ch(num)
  str = ""
  until num<1
    num -= 1
    str << (65+num%26).chr
    num /= 26
  end
  str.reverse
end
def ch_to_num(ch)
  num = 0
  ch.each_codepoint{|x| num = 26 * num + x - 64}
  num
end
n = gets.to_i
n.times do
  input = gets.chomp
  if input =~ /R\d+C\d+/
    row, col = input.scan(/R(\d+)C(\d+)/).first.map(&:to_i)
    puts "#{num_to_ch(col)}#{row}"
  else
    col, row = input.scan(/([[:upper:]]+)(\d+)/).first
    puts "R#{row}C#{ch_to_num(col)}"
  end
end

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            if this_char == 0
                this_char = 26
                col_num -= 1
            end
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

$table = ["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 to_E(x)
    b = ""
    t = true
    while x > 26 do
        if x % 26 == 0 then
            str = to_E(x-1)
            str[-1] = "Z"
            b = str + b
            x = 0
            t = false
        else
            b = $table[(x % 26) - 1] + b
            x /= 26
        end
    end
    if t then
        b = $table[x-1] + b
    end
    return b
end

def to_T(x)
    str = x.gsub(/[0123456789]/, "*")
    k = str.index("*")
    str1 = str[0...k]
    r = 0
    q = 26
    n = str1.size
    n.times do |i|
        r += ($table.index(str1[i]) + 1)*q**(n-i-1)
#       p (n-i-1)
#       p $table.index(str1[i]) + 1
#       p r
    end
    result = "R" + x[k..-1] + "C" + r.to_s
    return result
end

n = gets.to_i
ind = []
outd = []
n.times do |i|
    ind[i] = gets.chomp
    r = ind[i].index("R")
    c = ind[i].index("C")
    str = ind[i].gsub(/[ABDEFGHIJKLMNOPQSTUVWXYZ]/, "*")
    k = str.index("*")
    if r && c && !k && c-r>1 then
        ind[i] = to_E(ind[i][c+1..-1].to_i) + ind[i][r+1...c]
    else
        ind[i] = to_T(ind[i])
    end
end
n.times do |i|
    puts "#{ind[i]}"
end

def f(s)
	r=0
	s.each_byte{|c| r=r*26+c-64}
	r
end
def g(n)
	r=""
	while n>0 do
		x=n%26
		if x==0 then
			x=26
			n-=x
		end
		r=(x+64).chr+r
		n/=26
	end
	r
end
n=gets.to_i
n.times{
	s=gets
	if s=~/^([A-Z]+)(\d+)$/ then
		puts "R"+$2.to_s+"C"+f($1).to_s
	end
	if s=~/R(\d+)C(\d+)/ then
		puts g($2.to_i)+$1
	end
}

n=gets.chomp.to_i
data=[]

alpha=['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']
a=0

while a<n
	b=gets.chomp
	data.push(b)
	a+=1
end

osn=26
data.each do |t|
	word=t
	if word[0]=='R'
		flag=false
		flag1=0
		for i in(2..word.length-2)
			if word[i]=='C'
				flag1=i
				break
			end
		end

		flag2=[]
		z=0
		for i in(1..flag1)
			if word[i].to_i!=0
				z+=1
			end
		end

		if z!=0
			flag=true
		end

		r=[]
		c=[]

		pos=0
		if flag
			for i in(1..word.length-2)
				if word[i]!='C'
					r.push(word[i])
				else
					pos=i
					break
				end
			end
			for i in((pos+1)..word.length-1)
				c.push(word[i])
			end
			rows=r.join.to_i
			cells=c.join.to_i

			cs=[]

			a=0
			while cells>0
				b=cells%osn
				cs.push(alpha[b-1])
				if b==0
					cells-=(b+26)
				else
					cells-=b
				end
				cells/=osn
			end

			cs.reverse!
			cs.push(rows)

			puts cs.join
		else
			sn=[]
			a=0
			while word[a].to_i==0
				sn.push(word[a])
				a+=1
			end

			number=[]
			for i in(a..word.length-1)
				number.push(word[i])
			end
			numb=number.join.to_i

			sn.reverse!
			rw=0
			for i in(0..sn.length-1)
				rw+=(alpha.index(sn[i])+1)*osn**i
			end

			answer=[]
			answer.push('R')
			answer.push(numb)
			answer.push('C')
			answer.push(rw)
			puts answer.join
		end
	else
		sn=[]
		a=0
		while word[a].to_i==0
			sn.push(word[a])
			a+=1
		end

		number=[]
		for i in(a..word.length-1)
			number.push(word[i])
		end
		numb=number.join.to_i

		sn.reverse!
		rw=0
		for i in(0..sn.length-1)
			rw+=(alpha.index(sn[i])+1)*osn**i
		end

		answer=[]
		answer.push('R')
		answer.push(numb)
		answer.push('C')
		answer.push(rw)
		puts answer.join
	end
end

arr=("A".."Z").to_a
gets.to_i.times{
	s=gets.chomp
	if /R\d+C\d+/.match(s) then
		s.slice!(0)
		r,c=s.split("C").map{|e| e.to_i}
		str=""
		c=c-1
		while c>25
			str<<arr[c%26]
			c=(c-c%26-1)/26
		end
		str<<arr[c%26]
		puts (str.reverse)<<r.to_s
	else
		c1=/\D+/.match(s)
		r1=/\d+/.match(s)
		c26=1
		ansC=0
		c1.to_s.reverse.chars{|e|
			ansC+=(arr.index(e)+1)*c26
			c26*=26
		}
		puts "R"+r1.to_s+"C"+ansC.to_s
	end
}

n = STDIN.gets
n.to_i.times do |i|
    a = STDIN.gets
    if a =~ /\d+[A-Z]+/
        r = a.split(/[A-Z]/)[1]
        c = a.split(/[A-Z]/)[2].to_i
        completeAddress = Array.new
        while (c != 0)
            if c%26 == 0
                completeAddress.push('Z')
                c /= 26
                c -= 1
            else
                completeAddress.push((c%26 + 64).chr)
                c /= 26
            end

        end
        completeAddress = completeAddress.reverse.join("")
        completeAddress += r + "\n"
        print completeAddress
    else
        c = a[0,a=~/\d/]
        r = a.gsub(/[A-Z]+/,"")
        realrow = 0
        c.bytes.each do |i|
            realrow *= 26
            realrow += (i - 64)
        end
        print "R" + r.strip + "C" + realrow.to_s + "\n"
    end
end

def a(s)
  y = s.split(/C|R/)[1].to_i
  x = s.split(/C|R/)[2].to_i

  base = 26
  count = 1
  digits = 1
  while (count * base < x)
    x -= (count *= base)
    digits += 1
  end

  c = ''
  x -= 1
  digits.times do
    c = (65 + x % 26).chr + c
    x /= 26
  end

  puts "#{c}#{y}"
end

def b(s)
  x = s.split(/\d/)[0]
  y = s.split(/[^\d]/).last

  c = 0

  x.bytes.each do |l|
    c = 26 * c + (l - 65)
  end

  base = 1
  (x.size - 1).times do
    c += (base *= 26)
  end
  c += 1

  puts "R#{y}C#{c}"
end

gets.to_i.times do
  s = gets

  if s[0] == 'R' and s.bytes[1] < 65 and s.size > 2 and s.include?('C')
    a(s)
  else
    b(s)
  end
end

d=['', *?A..'BEAAA']

def t s
        p=a=0
        s.reverse!

        s.each_char{|c|
                a+= (c.ord - 'A'.ord + 1) * 26**p
                p+=1
        }

        a
end

n=gets.to_i

n.times{
        l=gets.strip

        if /R(\d+)C(\d+)/.match l
                puts "#{d[$2.to_i]}#{$1}"
        else
                a, b = l.scan(/([A-Z]+)([0-9]+)/)[0]
                puts "R#{b}C#{t a}"
        end
}

arr = STDIN.read.split("\n")
n = arr[0].to_i

1.upto(n).each do |i|
  str = arr[i]
  match = str.match(/R([0-9]+)C([0-9]+)/)

  if match
    row = match[2].to_i
    col = match[1]

    r = row
    str = ""
    while(r > 0) do
      val = (r-1) % 26
      str += (val + 65).chr
      r = (r-1)/26
    end
    str = str.reverse
    str += col
    puts str
  else
    match = str.match(/([A-Z]+)([0-9]+)/)
    col = match[1]
    row = match[2]

    s = 0
    rev = col.reverse.split("")
    rev.each_index do |i|
      chr = (rev[i][0].ord - 65 + 1) * ( 26 ** i )
      s += chr
    end

    puts "R#{row}C#{s}"
  end
end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #

def numToAZ(col)
  if col > 0
    numToAZ((col-1)/26) + ('A'.ord + (col-1)%26).chr
  else
    ""
  end
end

def to_CX(row, column)
  return numToAZ(column.to_i) + row
end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def to_RXCY(row, column)

  azLen = ('A'..'Z').to_a.length

  columnInt = 0
  column.reverse.each_char.each_with_index { |chr, idx|
    columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx
  }

  return "R#{row}C#{columnInt}"

end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def translate(coord)
  if coord =~ /^R(\d+)C(\d+)$/
    to_CX($1, $2)
  elsif coord =~ /^([A-Z]+)(\d+)/
    to_RXCY($2, $1)
  end
end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Main
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

gets.to_i.times {
  puts translate(gets.strip)
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def to_1var(row, column)

  az = ('A'..'Z').to_a
  azLen = az.length()

  columnAZ = ""
  columnInt = column.to_i

  while columnInt > 0
    idx = columnInt % azLen
    columnAZ.insert(0, az[idx-1])
    columnInt = (columnInt / azLen) - ((idx == 0)? 1 : 0)
  end

  return columnAZ + row

end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def to_2var(row, column)

  azLen = ('A'..'Z').to_a.length

  columnInt = 0
  column.reverse.each_char.each_with_index { |chr, idx|
    columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx
  }

  return "R#{row}C#{columnInt}"

end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def translate(coord)
  if coord =~ /^R(\d+)C(\d+)$/
    to_1var($1, $2)
  elsif coord =~ /^([A-Z]+)(\d+)/
    to_2var($2, $1)
  end
end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Main
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

gets.to_i.times {
  puts translate(gets.strip)
}

n=gets.chomp.to_i
n.times {
    s=gets.chomp.to_s
    s.scan(/^R([0-9]+)C([0-9]+)$/)
    unless !$~
        r=$~[1]
        c=$~[2].to_i
        remainder=-1
        g=""
        while c>0
            remainder=c%26
            #print ("#{remainder} ")
            if(remainder==0)
                g+="Z"
                c-=26
            else
                g+=(remainder+64).chr
                c-=remainder
            end
            #puts (g)
            c/=26
        end
        print(g.reverse)
        puts (r)
        next
    end
    s.scan(/^([A-Z]+)([0-9]+)$/)
    unless !$~
        c=$~[1]
        r=$~[2]
        k=1
        sum=0
        i=1
        len=c.length
        while i<=len
            #puts (i)
            hold=(c.getbyte(-1*i)-64)*k
            #puts ("hold = #{hold}")
            sum+=hold
            k*=26
            i+=1
        end
        puts ("R#{r}C#{sum}")
    end

}

$itoc =['Z'] +  ('A'..'Z').to_a
$ctoi = Hash.new
26.times{|i| $ctoi[$itoc[i+1]] = i+1}

def change str
 if str =~ /R(\d+)C(\d+)/
   return toAlph($2.to_i)+$1
 else
   str =~ /([A-Z]+)(\d+)/
   return 'R'+$2+'C'+toNum($1)
 end
end
def toAlph x
  ret = ''
  while x>0 do
    ret = $itoc[x%26] + ret
    x -= 26 if x%26 == 0
    x /= 26
  end
  return ret
end
def toNum x
  ret = 0
  x.reverse!
  x.size.times do |i|
    ret += ($ctoi[x[i]] * (26**i))
  end
  return ret.to_s
end

n = gets.to_i
n.times do
  puts (change gets)
end

class SpreadSheets
    def main
        numberOfLines = gets.to_i
        coordinates = Array.new(numberOfLines)

        i = 0
        while i < numberOfLines
            coordinates[i] = gets
            i += 1
        end

        puts convert(coordinates)
    end

    def convert(coordinates)
        result = Array::new
        numericDef = /R(\d+)C(\d+)/
        alphanumericDef = /([a-zA-Z]+)(\d+)/

        coordinates.each do |coordinate|
            if (numericDef.match(coordinate))
                matches = numericDef.match(coordinate)
                row = matches[1]
                column = matches[2]
                convertedColumn = convertNumToAlpha(column.to_i)
                result.push("#{convertedColumn}#{row}")
            elsif (alphanumericDef.match(coordinate))
                matches = alphanumericDef.match(coordinate)
                row = matches[2]
                column = matches[1]
                convertedColumn = convertAlphaToNum(column)
                result.push("R#{row}C#{convertedColumn}")
            end
        end

        return result
    end

    def convertNumToAlpha(num)
        result = String::new

        zeroLetter = 'A';
        base26 = 26;
        loop do
            num -= 1;
            remainder = num % base26;
            result = "#{(zeroLetter.ord + remainder).chr}#{result}"
            num /= base26;
            break if (num == 0)
        end

        return result
    end

    def convertAlphaToNum(alpha)
        result = 0

        zeroLetter = 'A'
        currentOrderOfMagnitude = 1
        base26 = 26
        alpha.split("").reverse_each do |letter|
            convertedDigit = letter.ord - zeroLetter.ord + 1
            result += currentOrderOfMagnitude * convertedDigit
            currentOrderOfMagnitude *= base26
        end

        return result.to_s
    end
end

SpreadSheets::new.main

def to_num s
    num = 0
    s.size.times do |i|
        num *= 26
        num += s[i].ord - 'A'.ord + 1
    end
    return num
end

def to_letters num
    s = ""
    while num > 0
        mod = num % 26
        if mod == 0
            mod = 26
            num -= 1
        end
        s += ('A'.ord + mod - 1).chr
        num /= 26
    end
    return s.reverse
end

gets.to_i.times do
    s = gets
    if s =~ /R\d+C\d+/
        r, c = s.tr("RC", " ").split.map &:to_i

        puts "#{to_letters c}#{r}"

    elsif s =~ /[A-Z]+\d+/
        r = s[/\d+/].to_i
        c = to_num(s[/[A-Z]+/])

        puts "R#{r}C#{c}"
    end
end

n = Integer(gets)
coo = Array.new
for i in 0...n
    coo[i] = Array.new
    input = gets.chomp
    coo[i] = input
end

class Cell
    attr_accessor :row, :column

    def initialize(row,column,value)
        @row = row
        @column = column
    end
end

    def rc_name_to_cell(rc_name)
        rc_name = rc_name[1,rc_name.length - 1]
        nums = rc_name.split("C")
        c_row = Integer(nums[0])
        c_column = Integer(nums[1])
        return c_row, c_column
    end

    def cell_to_excel_name(c_row,c_column)
        name = ""
        while (c_column > 0) do
            c_column -= 1
            name += (c_column % 26 + 'A'.ord).chr
            c_column = c_column / 26
        end
        return name.reverse + c_row.to_s
    end

    def excel_name_to_cell(excel_name)
       c_row = Array.new
       c_column = Array.new
       for i in 0...excel_name.length
           if excel_name[i] >= "0" && excel_name[i] <= "9"
               c_row.push(excel_name[i])
           else
               c_column.push(excel_name[i])
           end
       end
       sov = 0
       for i in 0 ...c_column.length
           sov += (c_column[i].ord - "A".ord + 1) * 26 ** (c_column.length - i - 1)
       end
       return c_row.join.to_i, sov
    end

    def cell_to_rc_name(c_row,c_column)
        print "R" + c_row.to_s + "C" + c_column.to_s
    end

def sov(coo)
    c = 0
    a = -1
    b = -1
    for j in 0...coo.length
        if coo[j] == "R"
            a = j
        elsif coo[j] == "C"
            b = j
        end
    end
    if a != -1 && b != -1
        for m in a + 1...b
            if coo[m] > "0" && coo[m] <= "9"
                c = 1
            end
        end
    end
    u = 0
    v = 0
    if c == 1
        u, v = rc_name_to_cell(coo)
        return cell_to_excel_name(u, v)
    else
        u, v = excel_name_to_cell(coo)
        return cell_to_rc_name(u, v)
    end
end
for i in 0...n
    puts sov(coo[i])
end

n = Integer(gets)
coo = Array.new
for i in 0...n
    coo[i] = Array.new
    input = gets.chomp
    coo[i] = input
end

class Cell
    attr_accessor :row, :column

    def initialize(row,column,value)
        @row = row
        @column = column
    end
end

    def rc_name_to_cell(rc_name)
        rc_name = rc_name[1,rc_name.length - 1]
        nums = rc_name.split("C")
        c_row = Integer(nums[0])
        c_column = Integer(nums[1])
        return c_row, c_column
    end

    def cell_to_excel_name(c_row,c_column)
        name = ""
        while (c_column > 0) do
            c_column -= 1
            name += (c_column % 26 + 'A'.ord).chr
            c_column = c_column / 26
        end
        return name.reverse + c_row.to_s
    end

    def excel_name_to_cell(excel_name)
       c_row = Array.new
       c_column = Array.new
       for i in 0...excel_name.length
           if excel_name[i] >= "0" && excel_name[i] <= "9"
               c_row.push(excel_name[i])
           else
               c_column.push(excel_name[i])
           end
       end
       sov = 0
       for i in 0 ...c_column.length
           sov += (c_column[i].ord - "A".ord + 1) * 26 ** (c_column.length - i - 1)
       end
       return c_row.join.to_i, sov
    end

    def cell_to_rc_name(c_row,c_column)
        print "R" + c_row.to_s + "C" + c_column.to_s
    end

for i in 0...n
    c = 0
    a = -1
    b = -1
    for j in 0...coo[i].length
        if coo[i][j] == "R"
                        a = j
                elsif coo[i][j] == "C"
                        b = j
        end
    end
    if a != -1 && b != -1
        for m in a + 1...b
            if coo[i][m] > "0" && coo[i][m] <= "9"
                c = 1
            end
        end
    end
    if c == 1
        u, v = rc_name_to_cell(coo[i])
        print cell_to_excel_name(u, v)
        puts
    else
        u, v = excel_name_to_cell(coo[i])
        print cell_to_rc_name(u, v)
        puts
    end

end

class Integer
  private
  LETTERS = ["Z"].concat(("A".."Y").to_a)

  public
  def to_ab
    number = self
    ab = ""
    while(number != 0) do
      letter_index = number % 26
      ab << LETTERS[letter_index]
      number /= 26
      if(letter_index == 0) then number -= 1 end
    end
    return ab.reverse
  end
end

class String
  private
  LETTERS = ("A".."Z").to_a

  public
  def to_rc
    rstring = self.clone.reverse!
    rc = 0
    rstring.length.times {
    |i|
      rc += ((LETTERS.index(rstring[i,1]) + 1) * (26 ** i))
    }
    return rc.to_s
  end
end

def rc_ab(rc)
  row, column = rc.scan(/\d+/)
  column = column.to_i.to_ab
  ab = column << row
  return ab
end

def ab_rc(ab)
  column, row = ab.scan(/([A-Z]+)(\d+)/)[0]
  column = column.to_rc
  rc = "R" << row << "C" << column
  return rc
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

def solve
  ans = ""
  input = gets
  #R23C55
  if (/^R\d+C\d+/ =~ input)
    r,c = input.scan(/\d+/).map(&:to_i)
    while c > 0
      c -= 1
      ans += ('A'.ord + c%26).chr
      c /= 26
    end
    ans.reverse!
    ans += r.to_s
  elsif /.\d+/ =~ input
    #BC23
    c = input.scan(/[A-Z]+/) #BC
    r = input.scan(/\d+/)#23
    ans += "R" + r.inject(""){|i,j| i + j} + "C" + ((0..c[0].size-1).inject(0){|i,j| i+26**j} + c[0].tr("A-Z","0-9A-Z").to_i(26)).to_s
  end
  puts ans
end

n = gets.to_i
n.times{ solve}

def solve
  ans = ""
  input = gets
  if (/^R\d+C\d+/ =~ input)
    r,c = input.scan(/\d+/).map(&:to_i)
    while c > 0
      c -= 1
      ans += ('A'.ord + c%26).chr
      c /= 26
    end
    ans.reverse!
    ans += r.to_s
  else
    c = input.scan(/[A-Z]+/).reverse! #BC
    r = input.scan(/\d+/) #23
    ans += "R"
    r.each {|tmp| ans += tmp.to_s}
    ans += "C"
    base = 1
    col  = 0
    c[0].reverse!
    for i in 0...c[0].size do
      col += (c[0][i].ord-'A'.ord+1)*base
      base *= 26
    end
    ans += col.to_s
  end
  puts ans
end

n = gets.to_i
n.times{ solve}

n = gets.to_i

def gao(val)
  ret = ""
  while val > 0
    if val % 26 == 0
      ret.concat('Z')
      val -= 1
    else
      ret.concat((val % 26 + 65 - 1).chr)
    end
    val /= 26
  end
  ret.reverse!
end

n.times do
  s = gets
  m = /R(\d+)C(\d+)/.match(s)
  if m != nil
    val = m[2].to_i
    puts "#{gao(val)}#{m[1]}"
  else
    m = /([A-Z]+)(\d+)/.match(s)
    col = m[1]
    col.reverse!
    cnt, base = 0, 1
    col.length.times do |i|
      cnt += (col[i].ord - 'A'.ord + 1) * base
      base *= 26
    end
    puts "R#{m[2]}C#{cnt}"
  end
end

n = gets.to_i

def gao(val)
  ret = ""
  while val > 0
    if val % 26 == 0
      ret.concat('Z')
      val -= 26
    else
      ret.concat((val % 26 + 65 - 1).chr)
    end
    val /= 26
  end
  ret.reverse!
end

n.times do
  s = gets
  m = /R(\d+)C(\d+)/.match(s)
  if m != nil
    val = m[2].to_i
    puts "#{gao(val)}#{m[1]}"
  else
    m = /([A-Z]+)(\d+)/.match(s)
    col = m[1]
    col.reverse!
    cnt, base = 0, 1
    col.length.times do |i|
      cnt += (col[i].ord - 'A'.ord + 1) * base
      base *= 26
    end
    puts "R#{m[2]}C#{cnt}"
  end
end

#!/usr/bin/ruby
def fromcell(s)
  r=0
  s.each_byte{|i|
    r=r*26+i-64
  }
  return r
end

def tocell(n)
  r=""
  while n>0 do
    x=n%26
    if x==0 then x=26; n-=26 end
    r=(x+64).chr+r
    n/=26
  end
  return r
end

n=gets.chomp.to_i
n.times{|z|
  s=gets.chomp
  if s=~/^([A-Z]+)(\d+)$/ then puts "R"+$2.to_s+"C"+fromcell($1).to_s end
  if s=~/R(\d+)C(\d+)/ then puts tocell($2.to_i)+$1.to_s end
}

n = gets.to_i
row, col, string = nil
$alf = ('A'..'Z').to_a

def int_to_symbolyc(int)
  result = ''
  mult = 1
  while int > 0
    to_sub = int % 26
    index = (to_sub - 1 % 26)
    to_sub = 26 if to_sub==0
    result = $alf[index] + result
    int -= to_sub
    int = int / 26
  end
  result
end

def sym_to_int(string)
  result = 0
  a_code = 'A'.bytes.first
  mult = 1
  string.reverse.bytes.each_with_index do |char, i|
    to_add = char - a_code + 1
    to_add *= mult
    result += to_add
    mult *= 26
  end
  result
end

n.times do
  string = gets
  if matches = string.match(/R(\d+)C(\d+)/)
    row, col = matches[1], matches[2]
    puts "#{int_to_symbolyc(col.to_i)}#{row}"
  else
    matches = string.match(/([A-Z]+)(\d+)/)
    col, row = matches[1], matches[2]
    puts "R#{row}C#{sym_to_int(col)}"
  end
end

n = gets.to_i
n.times do
	str = gets.chomp

	if re  = str.match(/^R(\d+)C(\d+)$/)
		c = re[2].to_i
		s = ""
		while c != 0
			mod = c % 26
			if mod == 0
				mod = 26
				c -= mod
			end
			s << (mod + 64).chr
			c /= 26
		end
		print s.reverse, re[1], "\n"
	elsif re  = str.match(/^([A-Z]+)(\d+)$/)
		c = 0
		re[1].each_byte do |char|
			c = char - 64 + c * 26
		end
		print "R", re[2], "C", c, "\n"
	end
end

n = gets.to_i
for x in gets("").split.take(n)
    if x[/R(\d+)C(\d+)/]
        a = $2.to_i - 1
        t = ("A".."Z").to_a.join[a%26]
        a = a.div 26
        until a == 0
            b,c = (a-1).divmod(26)
            t = ("A".."Z").to_a.join[c] + t
            a = b
        end
        puts t + $1
    else
        puts "R#{x[/\d+/]}C#{x[/\D+/].chars.inject(0){|i,j|i*26+j.ord-"A".ord+1}}"
    end
end

# Codeforces, Problem 1B
# http://codeforces.com/contest/1/problem/B
# Nate Collings

def first_int(cell)
  cell.split('').each_with_index do |char, i|
    begin
      Integer(char)
      return i
    rescue ArgumentError
    end
  end
end

def abc_to_int(str)
  num = 0
  power = 1
  str.reverse.split('').each do |char|
    num += (char.ord - 'A'.ord + 1) * power
    power *= 26
  end
  num
end

def convert_row_col_to_standard(r, c)
  dividend = c
  column = ''
  while dividend > 0
    remainder = (dividend - 1) % 26
    column = (65 + remainder).chr + column
    dividend = ((dividend - remainder) / 26).to_i
  end
  "#{column}#{r}"
end

def to_standard(cell)
  c_index = cell.index('C')
  row = cell[1...c_index].to_i
  col = cell[c_index+1..-1].to_i
  convert_row_col_to_standard(row, col)
end

def to_rxcy(cell)
  r_index = first_int(cell)
  col = abc_to_int(cell[0...r_index])
  row = cell[r_index..-1]
  "R#{row}C#{col}"
end

def is_rxcy?(cell)
  /R[0-9]+C[0-9]+/.match(cell)
end

gets.chomp.to_i.times do
  cell = gets.chomp
  if is_rxcy?(cell)
    puts to_standard(cell)
  else
    puts to_rxcy(cell)
  end
end

n = gets.to_i
1.upto(n) do
  str = gets
  state = 0
  0.upto(str.size-1) do |i|
    if str[i].ord>=48 and str[i].ord<=57
      state+=1 if state%2==0
    else
      state+=1 if state%2==1
    end
  end
  if state==2
    col = nil
    row = nil
    0.upto(str.size-1) do |i|
      if str[i].ord>=48 and str[i].ord<=57
        col = str[0..i-1]
        row = str[i..-1].strip
        break
      end
    end
    coln = 0
    0.upto(col.size-1) do |i|
      coln *= 26
      coln += col[i].ord-64
    end
    puts "R#{row}C#{coln}"
  else
    row = nil
    col = nil
    ci = nil
    0.upto(str.size-1) do |i|
      if str[i].ord == 67
        ci = i
      end
    end
    row = str[1..ci-1]
    col = str[ci+1..-1].to_i
    cols = ""
    while col>0
      if col%26==0
        cols = "Z" + cols
        col = (col-1)/26
      else
        cols = (col%26+64).chr + cols
        col /= 26
      end
    end
    puts cols+row
  end
end

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if (a.include?("R") && a.include?("C")) #como el metodo random tiene R&C
			ir=a.index("R")
			ic=a.index("C")

			if a.index("R")==0
				if a.index("C")==1
					return true
				else
					num_char=0
					0.upto(a.size-1) do |j|
						if (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str
							num_char+=0
						else
							num_char+=1
						end
					end

					return num_char==2? false : true
				end
			else
				return true
			end
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array) #TRUE ES excel
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end
	#IMPRIMIR RESULTADO
	puts $res

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  result = []
  begin
    x = column % 26
    x = 26 if 0 == x
    column = (column - x) / 26

    result.push x
  end while column > 0

  column_letters = ''
  result.reverse_each { |e|
    column_letters += (e.ord + 'A'.ord - 1).chr
  }

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

# Codeforces 1B
# TAG: Math

def rc2xls(r, c)
  a = []
  while c > 0 do a << ((c-1) % 26 + 1); c = (c-a.last)/26 end
  "#{a.reverse.reduce("") {|s, i| s += (i+64).chr }}#{r}"
end

def xls2rc(s)
  /(?<c>[A-Z]+)(?<r>\d+)/ =~ s
  c = c.split(//).map(&:ord).reduce(0) {|s, i| s = s*26 + i - 64 }
  "R#{r}C#{c}"
end

gets.to_i.times do
  puts /R(?<r>\d+)C(?<c>\d+)/ =~ (s = gets) ? rc2xls(r.to_i, c.to_i) : xls2rc(s)
end

# Codeforces 1B
# TAG: Math

def rc2xls(r, c)
  a = []
  while c>0
    t = ((c-1)%26+1)
    a << t
    c = (c-t)/26
  end
  "#{a.reverse.reduce("") {|s,i| s += (i+64).chr }}#{r}"
end

def xls2rc(s)
  /(?<c>\D+)(?<r>\d+)/ =~ s
  "R#{r}C#{c.split(//).map(&:ord).reduce(0) {|s, i| s = s*26+i-64 }}"
end

gets.to_i.times do
  puts /R(?<r>\d+)C(?<c>\d+)/ =~ (s = gets) ? rc2xls(r, c.to_i) : xls2rc(s)
end

def f(s)
    r=0
    s.each_byte{|c| r=r*26+c-64}
    r
end
def g(n)
    r=""
    while n>0 do
        x=n%26
        if x==0 then
            x=26
            n-=x
        end
        r=(x+64).chr+r
        n/=26
    end
    r
end
n=gets.to_i
n.times{
    s=gets
    if s=~/^([A-Z]+)(\d+)$/ then
        puts "R"+$2.to_s+"C"+f($1).to_s
    end
    if s=~/R(\d+)C(\d+)/ then
        puts g($2.to_i)+$1
    end
}

def a_to_n(line)
    length = line.length
    i = 0
    sum = 0
    while i < length
        sum = sum * 26 + (line[i].ord - 'A'.ord + 1)
        i = i + 1
    end
    return sum
end

def n_to_a(line)

    row_str = ""
    row_num = line.to_i
    while row_num > 0
        if(row_num % 26 != 0)
            row_str.prepend( (64 + row_num % 26).chr)
            row_num = row_num/26
        else
            row_str.prepend('Z')
            row_num = row_num/26 - 1
        end

    end
    return row_str

end

def xy_to_rc(line)
    col_size = line =~ /[0-9]/

    col_str = line[0...col_size]
    row_str = line[col_size...-1]

    col = a_to_n(col_str)
    row = row_str.to_i

    print("R")
    print(row)
    print("C")
    print(col)

end

def rc_to_xy(line)
    col_size = line =~ /[C]/

    row_str = line[1...col_size]
    col_str = line[col_size+1...-1]

    col = n_to_a(col_str)
    row = row_str.to_i

    print(col)
    print(row)
end

def isrc(line)
    if line[0] == 'R' && line[1] =~ /[0-9]/
        if line[2...-1].include? "C"
            return true
        end
    end
    return false
end

line_count = gets.to_i

while line_count > 0
    line_string = gets
    if isrc(line_string)
        rc_to_xy(line_string)
    else
        xy_to_rc(line_string)
    end
    print("\n")
    line_count = line_count-1
end

def to_ex d
  str = ""
  while d > 0
    d, a = (d - 1).divmod(26)
    str = (a + 65).chr + str
  end
  str
end

def ex_to str
  str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }
end

def solution str
  a, b = str.scan(/\d+/).map(&:to_i)
  if b
    "#{to_ex(b)}#{a}"
  else
    a, b = str.scan(/([A-Z]+)(\d+)/).first
    "R#{b}C#{ex_to(a)}"
  end
end

n = STDIN.gets.to_i
Array.new(n){ solution(STDIN.gets.chomp) }.each{ |v| print v, "\n" }

def convert(s)
    if (s =~ /R([0-9]+)C([0-9]+)/)
        c, r = $1, $2.to_i

        x = 1
        t = 26
        while r > t do
            r -= t
            x += 1
            t *= 26
        end

        d = []
        r -= 1
        for i in 0..x - 1
            d.push(r % 26)
            r /= 26
        end

        r = ""
        for i in (d.size - 1).step(0, -1)
            r += (d[i] + 'A'.ord).chr
        end
        return r + c
    elsif (s =~ /([A-Z]+)([0-9]+)/ )
        c, r = $1, $2

        ans, w = 0, 26
        for i in 1..c.size - 1
            ans += w
            w *= 26
        end

        cw = 0
        for i in 0..c.size - 1
            cw = c[i].ord - 'A'.ord + cw * 26
        end
        return 'R' + r + 'C' + (cw + 1 + ans).to_s
    end
end

n = gets.to_i

for cas in 0..n - 1
    s = gets
    ans = convert(s)
    puts(ans)
end

pattern_r = /R[0-9]+C[0-9]+/
pattern_a = /[A-Z]+[0-9]+/
n = gets.to_i
for i in 0...n
  s = gets
  if pattern_r =~ s
    x = s[/\d+/]
    y = s[/(C)(\d+)/, 2]
    y = y.to_i
    ans1 = ""
    while y != 0
      if y % 26 == 0
        ans1 = 'Z' << ans1
        y = y - 26
      else
        ans1 = ('A'.ord + y % 26 - 1).chr << ans1
      end
      y = y / 26
    end
    puts ans1 << x
  else
    x = s[/[A-Z]+/]
    y = s[/\d+/]
    ans1 = 0
    x.each_byte do |c|
      ans1 = ans1 * 26 + (c - "A".bytes.to_a[0]) + 1
    end
    puts "R" << y << "C" << ans1.to_s
  end
end

LettersCount = 'Z'.ord - 'A'.ord + 1

def intToLetters(i)
  result = ''
  while i > 0
    i -= 1
    letter = ('A'.ord + i % LettersCount).chr
    result << letter
    i /= LettersCount
  end
  result.reverse!
end

def lettersToInt(l)
  result = 0
  l.each_char {
    |char|
    result *= LettersCount
    result += char.ord - 'A'.ord + 1
  }
  result
end

def format2to1(r, c)
  intToLetters(c) + r.to_s
end

def format1to2(c, r)
  'R' + r + 'C' + lettersToInt(c).to_s
end

result = []

line = $stdin.gets
n = line.to_i
(1..n).each do
  line = $stdin.gets
  match = /R(\d+)C(\d+)/.match(line)
  if match
    captures = match.captures.map {|x| x.to_i}
    result << format2to1(captures[0], captures[1])
  elsif
    captures = /([^\d]+)(\d+)/.match(line).captures
    result << format1to2(captures[0], captures[1])
  end
end

result.each do |x|
  puts x
end

#!/bin/ruby

$ASCII_CODE_A = "A".bytes.to_a[0]

def to_alpha(n)
  ary = Array.new
  while n > 0
    c = ($ASCII_CODE_A + (n - 1) % 26).chr
    ary << c
    n = (n - 1) / 26
  end
  return ary.reverse.join
end

def to_number(as)
  n = 0
  as.each_byte do |c|
    n *= 26
    n += c - $ASCII_CODE_A + 1
  end
  return n
end

n = gets.to_i
(1..n).step do |i|
  input = gets
  if input =~ /^R(\d+)C(\d+)$/ then
    row = $1
    col = to_alpha($2.to_i)
    puts col + row
  elsif input =~ /^([A-Z]+)(\d+)$/ then
    row = $2
    col = to_number($1).to_s
    puts "R" + row + "C" + col
  end
end

#!/usr/bin/env ruby

def get_series_string(n)
  return "" if n == 0
  n = n - 1
  q = n/26
  r = n%26
  return "#{get_series_string(q)}#{(r+65).chr}"
end

def get_number_for_series(str)
  n = 0
  str.chars.each do | c |
    n = n * 26 + c.ord - 65 + 1
  end
  return n
end

s = gets.to_i
a = []
while s > 0 do
  a << gets.chomp!
  s -= 1
end

a.each do |e|
  parsed = e.scan(/([A-Z]+)(\d+)/)
  if parsed.length == 2
    puts "#{get_series_string(parsed[1][1].to_i)}#{parsed[0][1]}"
  elsif parsed.length == 1
    puts "R#{parsed[0][1]}C#{get_number_for_series(parsed[0][0])}"
  end
end

#!/usr/bin/env ruby

def get_series_string(n)
  str = ""
  while n > 0 do
    q = (n - 1) / 26
    r = (n - 1) % 26
    str = "#{(r + 65).chr}#{str}"
    n = q
  end
  return str
end

def get_number_for_series(str)
  n = 0
  str.chars.each do | c |
    n = n * 26 + c.ord - 65 + 1
  end
  return n
end

s = gets.to_i
s.times do
  e = gets.chomp!
  parsed = e.scan(/([A-Z]+)(\d+)/)
  if parsed.length == 2
    puts "#{get_series_string(parsed[1][1].to_i)}#{parsed[0][1]}"
  elsif parsed.length == 1
    puts "R#{parsed[0][1]}C#{get_number_for_series(parsed[0][0])}"
  end
  s -= 1
end

r = /R\d+C\d+/
row_regex = /\d+/

n = gets.chomp.to_i

n.times do
   line = gets.chomp
   if line.match(r)
     row = line[1.. (line =~ /C/)].to_i
     c = line[(line =~ /C/)+1..-1].to_i
     a = 0; b = 0
     a = c
     res = ""
     while (a+26) > 26
        a = c / 26
  			b = c % 26 == 0 ? 26 : c % 26
  			a = c % 26 == 0 ? a - 1 : a
  			c = a
        res.prepend(((b-1) + 65).chr)
     end
     puts "#{res}#{row}"
   else
     num_index = line =~ row_regex
     row = line[num_index..line.length()]
     col = 0
     col_str = line[0..num_index-1]
     col_str.split('').map.with_index  do |chr, i|
       col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))
     end
     puts "R#{row}C#{col}"
   end
end

number_of_input=gets.to_i
input_arry=[]
i=0

loop do
	break if i==number_of_input
	input_arry[i]=gets.chomp
	i +=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash={}
i=0

loop do
	break if i==26
	@hash[alph[i]]=value[i]
	i+=1
end

def S1_to_S2 (a1)
	r=a1[0]
	i=1

	loop do
		break if a1[i].to_i !=0
		r =r + a1[i]
		i+=1
	end

	r1=r.length
	r2=a1.length
	c1= a1[0 .. (r1-1)].reverse
	row= a1[ r1 .. r2].to_i
	c=0
	i=0

	loop do
		break if i==c1.length
		c= c + (@hash[c1[i]]*(26**i))
		i+=1
	end

	puts "R#{row}C#{c}"
end

def S2_to_S1 (a1)
	s2=a1.split("").map{|s| s}
	r3=3
	s2.find {|i| r3=s2.index(i)+1 if i=='C'}
	i=s2[r3 .. (s2.length - 1)].join.to_i
	row=s2[1 .. (r3-2)].join.to_i
	str_c=""

	loop do
		i=i-26 if i>25 && i%26==0
		if i%26==0
		str_c = str_c + "Z"
		else
		str_c = str_c + @hash.key(i%26)
		end
		i=i/26
		break if i==0
	end

	str_c=str_c.reverse
	puts "#{str_c}#{row}"
end

i=0

loop do
    break if i==input_arry.length
	input1=input_arry[i]

	if 	input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0)
		S1_to_S2 (input1)
	elsif input1[0]=='R' && input1[1].to_i!=0
		k2=input1.split("")
		k=0
		k2.find{|s| k=1 if s=='C'}
		if k==1
			S2_to_S1(input1)
		else
			S1_to_S2 (input1)
		end
	end

	i +=1

end

number_of_input=gets.to_i
input_arry=[]
i_a=0

loop do
	break if i_a==number_of_input
	input_arry[i_a]=gets.chomp
	i_a +=1
end
value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash={}
i_b=0

loop do
	break if i_b==26
	@hash[alph[i_b]]=value[i_b]
	i_b+=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash2={}
i_b=0

loop do
	break if i_b==26
	@hash2[alph[i_b]]=value[i_b]
	i_b+=1
end
@hash2['Z']=0

def S1_to_S2 (a1)
	r=a1[0]
	i=1

	loop do
		break if a1[i].to_i !=0
		r =r + a1[i]
		i+=1
	end

	r1=r.length
	r2=a1.length
	c1= a1[0 .. (r1-1)].reverse
	row= a1[ r1 .. r2].to_i
	c=0
	i=0

	loop do
		break if i==c1.length
		c= c + (@hash[c1[i]]*(26**i))
		i+=1
	end

	puts "R#{row}C#{c}"
end

def S2_to_S1 (a1)
	s2=a1.split("").map{|s| s}
	r3=3
	s2.find {|i| r3=s2.index(i)+1 if i=='C'}
	i=s2[r3 .. (s2.length - 1)].join.to_i
	row=s2[1 .. (r3-2)].join.to_i
	str_c=""

	loop do
		i=i-26 if i>25 && i%26==0
		str_c = str_c + @hash2.key(i%26)
		i=i/26
		break if i==0
	end

	str_c=str_c.reverse
	puts "#{str_c}#{row}"
end

i_c =0

loop do
    break if i_c==input_arry.length
	input1=input_arry[i_c]

	if 	input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0)
		S1_to_S2 (input1)
	elsif input1[0]=='R' && input1[1].to_i!=0
		k2=input1.split("")
		k=0
		k2.find{|s| k=1 if s=='C'}
		if k==1
			S2_to_S1(input1)
		else
			S1_to_S2 (input1)
		end
	end

	i_c +=1

end

n = gets().to_i
for i in 1..n
	line = gets().split(/(\d+)/)
	if line.length >= 4
		col = line[3].to_i
		for j in 1..100
			break if 26**j >= col
			col -= 26**j
		end
		s = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
		puts s << line[1]
	else
		row = line[1]
		ans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26)
		for j in 1..line[0].length-1
			ans += 26**j
		end
		puts 'R' << row << 'C' << ans.to_s
	end
end

#!/usr/bin/ruby

$ord_A = "A".ord

def name2addr(name)
	addr = 0
	name.each_char do |c|
		addr = addr*26 + c.ord - $ord_A + 1
	end
	return addr
end

def addr2name(addr)
	name = ""
	while addr != 0
		addr -= 1
		name = (addr%26 + $ord_A).chr + name
		addr /= 26
	end
	return name
end

gets	# skip first line
while gets
	line = $_.chomp
	if m = /R(\d+)C(\d+)/.match(line)
		puts addr2name(m[2].to_i) + m[1]
	elsif m = /([A-Z]+)(\d+)/.match(line)
		puts "R" + m[2] + "C" + name2addr(m[1]).to_s
	else
		abort "bad_format"
	end
end

class SpreadsheetCoordinateConverter
  EXCEL_SYSTEM_BASE = 26

  class << self
    def convert(lines)
      lines.map do |line|
        if line =~ /R(\d+)C(\d+)/
          rc_to_excel($1.to_i, $2.to_i)
        elsif line =~ /([A-Z]+)(\d+)/
          excel_to_rc($1.to_s, $2.to_i)
        end
      end
    end

    private

    # R23C55 -> BC23
    def rc_to_excel(row, col)
      excel_col = ''
      while col > 0
        col -= 1
        excel_col << num_to_chr(col % EXCEL_SYSTEM_BASE)
        col /= EXCEL_SYSTEM_BASE
      end
      excel_col.reverse! + row.to_s
    end

    # BC23 -> R23C55
    def excel_to_rc(excel_col, row)
      col = 0
      power_multiplier = 1
      excel_col.reverse.each_char do |chr|
        col += (chr_to_num(chr) + 1) * power_multiplier
        power_multiplier *= EXCEL_SYSTEM_BASE
      end
      "R#{row}C#{col}"
    end

    def num_to_chr(num)
      (num + 'A'.ord).chr
    end

    def chr_to_num(chr)
      chr.ord - 'A'.ord
    end
  end
end

if __FILE__ == $0
  lineCount = gets.to_i
  lines = []
  lineCount.times { |line| lines << gets }
  SpreadsheetCoordinateConverter.convert(lines).each { |line| puts line }
end

arr = STDIN.read.split("\n")
n = arr[0].to_i

1.upto(n).each do |i|
  str = arr[i]
  match = str.match(/R([0-9]+)C([0-9]+)/)

  if match
    row = match[2].to_i
    col = match[1]

    r = row
    str = ""
    while(r > 0) do
      val = (r-1) % 26
      str += (val + 65).chr
      r /= 26
    end
    str = str.reverse
    str += col
    puts str
  else
    match = str.match(/([A-Z]+)([0-9]+)/)
    col = match[1]
    row = match[2]

    puts "A"
    s = 0
    rev = col.reverse.split("")
    puts "B"
    rev.each_index do |i|
    puts "rev[i]" + rev[i]
    puts rev[i].ord - 65 + 1
      chr = (rev[i].ord - 65 + 1) * ( 26 ** i )
      puts "chr:#{chr}"
      s += chr
    end

    puts "R#{row}C#{s}"
  end
end

#!/usr/bin/ruby
def fromcell(s)
  r=0
  s.length.times{|i|
    #r=r*26+s[i]-64
  }
  return r
end

def tocell(n)
  r=""
  while n>0 do
    r=(n%26+64).chr+r
    n/=26
  end
  return r
end

n=gets.chomp.to_i
n.times{|z|
  s=gets.chomp
  if s=~/^([A-Z]+)(\d+)$/ then puts "R"+$2.to_s+"C"+fromcell($1).to_s end
  if s=~/R(\d+)C(\d+)/ then puts tocell($2.to_i)+$1.to_s end
}
exit(0)

n = gets().to_i
for i in 1..n
	line = gets().split(/(\d+)/)
	if line[0] == 'R'
		col = line[3].to_i
		for j in 1..100
			break if 26**j >= col
			col -= 26**j
		end
		s = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
		puts s << line[1]
	else
		row = line[1]
		ans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26)
		for j in 1..line[0].length-1
			ans += 26**j
		end
		puts 'R' << row << 'C' << ans.to_s
	end
end

def n2s(n)
  s = ""
  while n > 0
    s = ("A".ord + n % 26 - 1).chr + s
    n /= 26
  end
  return s
end

def s2n(s)
  n = 0
  s.size.times do |i|
    n *= 26
    n += s[i].ord - "A".ord + 1
  end
  return n
end

n = gets.to_i
n.times do
  str = gets
  if str =~ /^([A-Z]+)(\d+)$/
    c_s = $1
    r = $2.to_i
    c = s2n(c_s)
    puts "R#{r}C#{c}"
  elsif str =~ /^R(\d+)C(\d+)$/
    r = $1.to_i
    c = $2.to_i
    c_s = n2s(c)
    puts "#{c_s}#{r}"
  end
end

alph = ['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']

n = gets.chomp.to_i

lines = []
n.times {lines << gets.chomp}
lines.each do |l|
    if (l =~ /R\d+C\d+/).nil?
        col = 0
        colstr = l.scan(/[A-Z]+/).first.split("")
        colstr.each_with_index do |ch, index|
            col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))
        end
        row = l.scan(/[0-9]+/).first
        puts "R#{row}C#{col}"
    else
        row = l.scan(/R([0-9]+)/).flatten.first
        col = l.scan(/C([0-9]+)/).flatten.first.to_i
        cols = ""
        remainder = 1
        loop do
            minus = remainder == 0 ? 2 : 1
            remainder = (col % 26)
            col = col / 26
            unless col == 0 and minus == 2 and remainder <= 1
                cols = alph[remainder - minus] + cols
            end
            break if col == 0
        end
        puts "#{cols}#{row}"
    end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_letters num
	ans=""
	digs=[*?A..?Z]

	num+=num/27

	while num!=0
		ans+=digs[num%27-1]
		num/=27
	end

	ans.reverse
end

def to_numbers str
	ans=0
	str.reverse!

	pow=0
	str.each_char{|c|
		ans+= (c.ord - 'A'.ord + 1) * 26**pow
		pow+=1
	}

	ans
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R(\d+)C(\d+)/.match line
		puts "#{to_letters $2.to_i}#{$1}"
	else
		p1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]
		puts "R#{p2}C#{to_numbers p1}"
	end
}

def to_ex d
  str = ""
  while d > 1
    d, a = d.divmod(26)
    str = (a + 64).chr + str
  end
  str
end

def ex_to str
  str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }
end

def solution str
  a, b = str.scan(/\d+/).map(&:to_i)
  if b
    "#{to_ex(b)}#{a}"
  else
    a, b = str.scan(/([A-Z]+)(\d+)/).first
    "R#{b}C#{ex_to(a)}"
  end
end

n = STDIN.gets.to_i
Array.new(n){ solution(STDIN.gets.chomp) }.each{ |v| print v, "\n" }

alph = ['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']

n = gets.chomp.to_i

lines = []
n.times {lines << gets.chomp}
lines.each do |l|
    if (l =~ /R\d+C\d+/).nil?
        col = 0
        colstr = l.scan(/[A-Z]+/).first.split("")
        colstr.each_with_index do |ch, index|
            col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))
        end
        row = l.scan(/[0-9]+/).first
        puts "R#{row}C#{col}"
    else
        row = l.scan(/R([0-9]+)/).flatten.first
        col = l.scan(/C([0-9]+)/).flatten.first.to_i
        cols = ""
        loop do
            remainder = (col % 26)
            cols = alph[remainder - 1] + cols
            col = col / 26
            break if col == 0
        end
        puts "#{cols}#{row}"
    end
end

number_of_input=gets.to_i
input_arry=[]
i_a=0

loop do
	break if i_a==number_of_input
	input_arry[i_a]=gets.chomp
	i_a +=1
end
puts "______________________"
value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash={}
i_b=0

loop do
	break if i_b==26
	@hash[alph[i_b]]=value[i_b]
	i_b+=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash2={}
i_b=0

loop do
	break if i_b==26
	@hash2[alph[i_b]]=value[i_b]
	i_b+=1
end
@hash2['Z']=0

def S1_to_S2 (a1)
	r=a1[0]
	i=1

	loop do
		break if a1[i].to_i !=0
		r =r + a1[i]
		i+=1
	end

	r1=r.length
	r2=a1.length
	c1= a1[0 .. (r1-1)].reverse
	row= a1[ r1 .. r2].to_i
	c=0
	i=0

	loop do
		break if i==c1.length
		c= c + (@hash[c1[i]]*(26**i))
		i+=1
	end

	puts "R#{row}C#{c}"
end

def S2_to_S1 (a1)
	s2=a1.split("").map{|s| s}
	r3=3
	s2.find {|i| r3=s2.index(i)+1 if i=='C'}
	i=s2[r3 .. (s2.length - 1)].join.to_i
	row=s2[1 .. (r3-2)].join.to_i
	str_c=""

	loop do
		i=i-26 if i>25 && i%26==0
		str_c = str_c + @hash2.key(i%26)
		i=i/26
		break if i==0
	end

	str_c=str_c.reverse
	puts "#{str_c}#{row}"
end

i_c =0

loop do
    break if i_c==input_arry.length
	input1=input_arry[i_c]

	if 	input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0)
		S1_to_S2 (input1)
	elsif input1[0]=='R' && input1[1].to_i!=0
		k2=input1.split("")
		k=0
		k2.find{|s| k=1 if s=='C'}
		if k==1
			S2_to_S1(input1)
		else
			S1_to_S2 (input1)
		end
	end

	i_c +=1

end

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if a.include?("R") && a.include?("C") #como el metodo random tiene R&C
			ir=a.index("R") #queremos el index de cada letra
			ic=a.index("C") #porque para q sea random, la diferencia debe ser 1
			return (ic-ir)==1? true : false
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+"#{parte_num}"+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array)
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end

	#IMPRIMIR RESULTADO
	puts $res

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            if this_char == 0
                this_char = 26
            end
            col_num -= 1
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  column_index = column.to_s(26).upcase
  column_letters = ''
  column_index.each_char do |c|
    if c.ord > '9'.ord
      column_letters += (c.ord + 9).chr
    else
      column_letters += (c.ord + 'A'.ord - '1'.ord).chr
    end
  end

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num = 0
	digits = [*?A..?Z]

	pow=1
	str.reverse.each_char{|c|
		d = digits.index(c) + 1

		num+=d*pow
		pow*=26
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_27 num
	ans = ""
	digits = [*?A..?Z]

	num = num.to_i
	while num!=0
		ans+=digits[num%27]
		num/=27
	end

	ans
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_27 b}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

#!/usr/bin/ruby
def fromcell(s)
  r=0
  s.length.times{|i|
    r=r*26+s[i]-64
  }
  return r
end

def tocell(n)
  r=""
  while n>0 do
    r=(n%26+64).chr+r
    n/=26
  end
  return r
end

n=gets.chomp.to_i
n.times{|z|
  s=gets.chomp
  if s=~/^([A-Z]+)(\d+)$/ then
puts "R"
#+$2.to_s+"C"+fromcell($1).to_s
end
  if s=~/R(\d+)C(\d+)/ then puts tocell($2.to_i)+$1.to_s end
}
exit(0)

n = STDIN.gets
n.to_i.times do |i|
    a = STDIN.gets
    if a =~ /\d+[A-Z]+/
        r = a.split(/[A-Z]/)[1]
        c = a.split(/[A-Z]/)[2].to_i
        completeAddress = Array.new
        while (c != 0)
            completeAddress.push((c%26 + 64).chr)
            c /= 26
        end
        completeAddress = completeAddress.reverse.join("")
        completeAddress += r + "\n"
        print completeAddress
    else
        c = a[0,a=~/\d/]
        r = a.gsub(/[A-Z]+/,"")
        realrow = 0
        c.bytes.each do |i|
            realrow *= 26
            realrow += (i - 64)
        end
        print "R" + r.strip + "C" + realrow.to_s + "\n"
    end
end

class SpreadSheets
    def main
        numberOfLines = gets.to_i
        coordinates = Array.new(numberOfLines)

        i = 0
        while i < numberOfLines
            coordinates[i] = gets
            i += 1
        end

        puts convert(coordinates)
    end

    def convert(coordinates)
        result = Array::new
        numericDef = /R(\d+)C(\d+)/
        alphanumericDef = /([a-zA-Z]+)(\d+)/

        coordinates.each do |coordinate|
            if (numericDef.match(coordinate))
                matches = numericDef.match(coordinate)
                row = matches[1]
                column = matches[2]
                convertedColumn = convertNumToAlpha(column.to_i)
                result.push("#{convertedColumn}#{row}")
            elsif (alphanumericDef.match(coordinate))
                matches = alphanumericDef.match(coordinate)
                row = matches[2]
                column = matches[1]
                convertedColumn = convertAlphaToNum(column)
                result.push("R#{row}C#{convertedColumn}")
            end
        end

        return result
    end

    def convertNumToAlpha(num)
        result = String::new

        zeroLetter = 'A';
        base26 = 26;
        loop do
            num -= 1;
            remainder = num % base26;
            result = "#{(zeroLetter.ord + remainder).chr}#{result}"
            num /= base26;
            break if (num == 0)
        end

        return result
    end

    def convertAlphaToNum(alpha)
        result = 0

        zeroLetter = 'A'
        currentExp = 1
        base26 = 26
        alpha.split("").reverse_each do |letter|
            convertedDigit = letter.ord - zeroLetter.ord
            result = result * currentExp + (convertedDigit + 1)
            currentExp *= base26
        end

        return result.to_s
    end
end

SpreadSheets::new.main

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if a.include?("R") && a.include?("C") #como el metodo random tiene R&C
			ir=a.index("R") #queremos el index de cada letra
			ic=a.index("C") #porque para q sea random, la diferencia debe ser 1
			return (ic-ir)==1? true : false
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array)
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end

	#IMPRIMIR RESULTADO
	puts $res

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  column_index = column.to_s(26)
  column_letters = ''
  column_index.each_char do |c|
    if c.ord > '9'.ord
      column_letters += (c.ord + 9).chr
    else
      column_letters += (c.ord + 'A'.ord - '1'.ord).chr
    end
  end

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            if this_char == 0
                this_char = 26
            end
            col_num /= 26
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

$table = ["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 to_E(x, y)
    b = ""
    if x % 26 == 0 then
        b = to_E(x-1, y)
        b[-y.size-1] = "Z"
    else
        while x > 26 do
            b = $table[(x % 26) - 1] + b
            x /= 26
        end
        b = $table[x-1] + b
        b += y
    end
    return b
end

def to_T(x)
    str = x.gsub(/[0123456789]/, "*")
    k = str.index("*")
    str1 = str[0...k]
    r = 0
    q = 26
    n = str1.size
    n.times do |i|
        r += ($table.index(str1[i])+1)*q**(n-i-1)
    end
    result = "R" + x[k..-1] + "C" + r.to_s
    return result
end

n = gets.to_i
ind = []
outd = []
n.times do |i|
    ind[i] = gets.chomp
    r = ind[i].index("R")
    c = ind[i].index("C")
    if r && c && c-r > 1 then
        ind[i] = to_E(ind[i][c+1..-1].to_i, ind[i][r+1...c])
    else
        ind[i] = to_T(ind[i])
    end
end
n.times do |i|
    puts "#{ind[i]}"
end

$letters = [""].concat(("A".."Z").to_a)

def rc_ab(rc)
  rc_a = rc.scan(/\d+/)
  rc_a[1] = rc_a[1].to_i
  s = ""

  while(rc_a[1] != 0) do
    s << $letters[rc_a[1] % 26]
    rc_a[1] /= 26
  end

  s = s.reverse << rc_a[0]
  return s
end

def ab_rc(ab)
  ab_c = /[A-Z]+/.match(ab)

  ab_s = ab_c.to_s.reverse
  ab_n = 0

  ab_s.length.times {
    |i|
    ab_n += $letters.index(ab_s[i,1]) * 26 ** i
  }

  s = "R" << ab_n.to_s << "C" << /\d+/.match(ab).to_s
  return s
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

letters = %w(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)

gets.to_i.times do
  input = gets.strip
  if input =~ /R(\d)+C/
    codes = input.gsub("R","").split("C").map(&:to_i)
    ans = ""
    codes[1]
    puts codes[1].inspect
    while codes[1] > 0 do
      ans << letters[(codes[1]%26-1)]
      puts codes[1].inspect
      codes[1] /= 26
      codes[1] -= 1
    end

    puts "#{ans.reverse}#{codes[0]}"
  else
    code = input.match(/([A-Z])+/).to_s
    sum = 0
    code.chars.each_with_index do |el,i|
      sum += (1+letters.index(el)) * (26**(code.size-i-1))
    end
    puts "R#{input.match(/([0-9])+/)}C#{sum}"
  end
end

num = gets.chomp.to_i
puts num
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num = 0
	digits = [*?A..?Z]

	pow=1
	str.reverse.each_char{|c|
		d = digits.index(c) + 1

		num+=d*pow
		pow*=26
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_27 num
	ans = ""
	digits = [*?A..?Z]

	num = num.to_i
	while num!=0
		ans = digits[num%26-1] + ans
		num/=26
	end

	ans
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_27 b}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

def solve(input)
  if (/R\d+C\d+/ =~ input) == nil
    fromBase26(input)
  else
    toBase26(input)
  end
end

def fromBase26(input)
  charByte = "A".bytes[0]
  numByte = "1".bytes[0]
  letters = Array.new
  numbers = Array.new

  input.chomp.each_byte do |byte|
    if byte < charByte
      numbers.unshift(byte-(numByte-1))
    else
      letters.unshift(byte-(charByte-1))
    end
  end

  rows = arrayToInt(numbers, 10)
  cols = arrayToInt(letters, 26)
  "R#{rows}C#{cols}"
end

def toBase26(input)
  input[0] = ""
  rows, cols = input.split("C")
  val = cols.to_i
  digits = []
  while val != 0
    digits.unshift(val%26)
    val /= 26
  end
  cols = ""
  for digit in digits
    val = digit + ("A".bytes[0]-1)
    cols += val.chr
  end
  cols + "#{rows}"
end

def arrayToInt(arr, base)
  curr = 1
  int = 0
  for val in arr
    int += val*curr
    curr *= base
  end
  int
end

n = gets.to_i
ans = Array.new(n, nil)
for i in (0...n)
  ans[i] = solve(gets)
end

for answer in ans
  puts answer
end

#!/usr/bin/env ruby

def convert(str)
  if str =~ /^R(\d+)C(\d+)$/
    rows, cols  = $1.to_i, $2.to_i
    cols -= 1
    a = []
    loop do
      a.unshift cols % 26
      cols /= 26
      break if cols == 0
    end
    "#{a.map{|i| (i + 65).chr}.join}#{rows}"
  elsif str =~ /^([A-Z]+)(\d+)$/
    cols = 0
    $1.size.times do |i|
      cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)
    end
    "R#{$2}C#{cols}"
  else
    "invalid arg"
  end
end

n = gets.to_i
lines = []
n.times do
  lines << convert(gets.chomp)
end

lines.each{|s| puts s}

class Integer
  private
  LETTERS = ["Z"].concat(("A".."Y").to_a)

  public
  def to_ab
    number = self
    ab = ""
    while(number != 0) do
      ab << LETTERS[number % 26]
      number /= 26
    end
    return ab.reverse
  end
end

class String
  private
  LETTERS = ("A".."Z").to_a

  public
  def to_rc
    rstring = self.clone.reverse!
    rc = 0
    rstring.length.times {
    |i|
      rc += ((LETTERS.index(rstring[i,1]) + 1) * (26 ** i))
    }
    return rc.to_s
  end
end

def rc_ab(rc)
  row, column = rc.scan(/\d+/)
  column = column.to_i.to_ab
  ab = column << row
  return ab
end

def ab_rc(ab)
  column, row = ab.scan(/([A-Z]+)(\d+)/)[0]
  column = column.to_rc
  rc = "R" << row << "C" << column
  return rc
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if a.include?("R") && a.include?("C") #como el metodo random tiene R&C
			if a.index("R")==0
				ir=a.index("R") #queremos el index de cada letra
				ic=a.index("C") #porque para q sea random, la diferencia debe ser 1
				return (ic-ir)==1? true : false
			else
				return true
			end
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array)
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end
	#IMPRIMIR RESULTADO
	puts $res

$letters = [""].concat(("A".."Z").to_a)

def rc_ab(rc)
  rc_a = rc.scan(/\d+/)
  rc_a[1] = rc_a[1].to_i
  s = ""

  while(rc_a[1] != 0) do
    s << $letters[rc_a[1] % 26]
    rc_a[1] /= 26
  end

  s = s.reverse << rc_a[0]
  return s
end

def ab_rc(ab)
  ab_c = /[A-Z]+/.match(ab)

  ab_s = ab_c.to_s.reverse
  ab_n = 0

  ab_s.length.times {
    |i|
    ab_n += $letters.index(ab_s[i,1]) * 26 ** i
  }

  s = "R" << ab_n.to_s << "C" << /\d+/.match(ab).to_s
  return s
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts("rc_ab")
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  column_index = column.to_s(26).upcase
  column_letters = ''
  column_index.each_char do |c|
    if c.ord > '9'.ord
      if '0' == c
        column_letters += 'Z'
      else
        column_letters += (c.ord + 9).chr
      end
    else
      column_letters += (c.ord + 'A'.ord - '1'.ord).chr
    end
  end

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_letters num
	ans=""
	digs=[*?A..?Z]

	while num!=0
		ans+=digs[num%26 - 1]
		num/=26
	end

	ans.reverse
end

def to_numbers str
	ans=0
	str.reverse!

	pow=0
	str.each_char{|c|
		ans+= (c.ord - 'A'.ord + 1) * 26**pow
		pow+=1
	}

	ans
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R(\d+)C(\d+)/.match line
		puts "#{to_letters $2.to_i}#{$1}"
	else
		p1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]
		puts "R#{p2}C#{to_numbers p1}"
	end
}

def to_ex d
  str = ""
  while d > 1
    d, a = d.divmod(26)
    str = (a + 64).chr + str
  end
  str
end

def ex_to str
  str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }
end

def solution str
  a, b = str.scan(/\d+/).map(&:to_i)
  if b
    "#{to_ex(b)}#{a}"
  else
    a, b = str.scan(/([A-Z]+)(\d+)/).first
    "R#{b}C#{ex_to(a)}"
  end
end

n = STDIN.gets.to_i
Array.new(n){ solution(STDIN.gets.chomp) }.each{ |v| p v }

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            if this_char == 0
                this_char = 26
            end
            col_num -= 1
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

def f(s)
	r=0
	s.each_byte{|c| r=r*10+c-64}
	r
end
def g(n)
	r=""
	while n>0 do
		x=n%26
		if x==0 then
			x=26
			n-=x
		end
		r=(x+64).chr+r
		n/=26
	end
	r
end
n=gets.to_i
n.times{
	s=gets
	if s=~/^([A-Z]+)(\d+)$/ then
		puts "R"+$2.to_s+"C"+f($1).to_s
	end
	if s=~/R(\d+)C(\d+)/ then
		puts g($2.to_i)+$1
	end
}

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num = 0
	digits = [*?A..?Z]

	pow = 0
	str.reverse.each_char{|c|
		d = digits.index(c)+1

		num+=d * 26**pow
		pow+=1
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_27 num
	ans = ""
	digits = [*?A..?Z]

	num = num.to_i
	while num!=0
		ans = digits[num%27-1] + ans
		num/=27
	end

	ans.reverse
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_27 b}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

arr = STDIN.read.split("\n")
n = arr[0].to_i

1.upto(n).each do |i|
  str = arr[i]
  match = str.match(/R([0-9]+)C([0-9]+)/)

  if match
    row = match[2].to_i
    col = match[1]

    r = row
    str = ""
    while(r > 0) do
      val = (r-1) % 26
      str += (val + 65).chr
      r /= 26
    end
    str = str.reverse
    str += col
    puts str
  else
    match = str.match(/([A-Z]+)([0-9]+)/)
    col = match[1]
    row = match[2]

    s = 0
    rev = col.reverse.split("")
    rev.each_index do |i|
      chr = (rev[i].ord - 65 + 1) * ( 26 ** i )
      puts "chr:#{chr}"
      s += chr
    end

    puts "R#{row}C#{s}"
  end
end

def n2s(n)
  s = ""
  while n > 0
    s = ("A".ord + n % 26 - 1).chr + s
    n /= 26
  end
  return s
end

def s2n(s)
  n = 0
  s.size.times do |i|
    n *= 26
    n += s[i].ord - "A".ord + 1
  end
  return n
end

n = gets.to_i
n.times do
  str = gets
  if str =~ /^([A-Z]+)(\d+)$/
    c_s = $1
    r = $2.to_i
    c = s2n(c_s)
    puts "R#{r}C#{c}"
  elsif str =~ /^R(\d+)C(\d+)$/
    r = $1.to_i
    c = $2.to_i
    c_s = n2s(c)
    puts "#{c_s}#{r}"
  end
end

def to_ex d
  str = ""
  while d > 1
    d, a = d.divmod(26)
    str = (a + 64).chr + str
  end
  str
end

def ex_to str
  str.chars.each.with_index.inject(0){ |z, (v, i)| z = z * 26 + (v.ord - 64) }
end

def solution str
  a, b = str.scan(/\d+/).map(&:to_i)
  if b
    p "#{to_ex(b)}#{a}"
  else
    a, b = str.scan(/([A-Z]+)(\d+)/).first
    p "R#{b}C#{ex_to(a)}"
  end
end

n = STDIN.gets.to_i
p Array.new(n){ solution(STDIN.gets.chomp) }

alph = ['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']

n = gets.chomp.to_i

lines = []
n.times {lines << gets.chomp}
lines.each do |l|
    if (l =~ /R\d+C\d+/).nil?
        col = 0
        colstr = l.scan(/[A-Z]+/).first.split("")
        colstr.each_with_index do |ch, index|
            col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))
        end
        row = l.scan(/[0-9]+/).first
        puts "R#{row}C#{col}"
    else
        row = l.scan(/R([0-9]+)/).flatten.first
        col = l.scan(/C([0-9]+)/).flatten.first.to_i
        cols = ""
        loop do
            remainder = (col % 26)
            cols = alph[remainder - 1] + cols
            col = col / 26
            break if col == 0
        end
        puts "#{cols}#{row}"
    end
end

alph = ['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']

n = gets.chomp.to_i

lines = []
n.times {lines << gets.chomp}
lines.each do |l|
    if (l =~ /R\d+C\d+/).nil?
        col = 0
        colstr = l.scan(/[A-Z]+/).first.split("")
        colstr.each_with_index do |ch, index|
            col += (alph.index(ch) + 1) * (26 ** (colstr.length - index - 1))
        end
        row = l.scan(/[0-9]+/).first
        puts "R#{row}C#{col}"
    else
        row = l.scan(/R([0-9]+)/).flatten.first
        col = l.scan(/C([0-9]+)/).flatten.first.to_i
        cols = ""
        remainder = 1
        loop do
            minus = remainder == 0 ? 2 : 1
            remainder = (col % 26)
            cols = alph[remainder - minus] + cols
            col = col / 26
            break if col == 0
        end
        puts "#{cols}#{row}"
    end
end

n = gets.to_i
1.upto(n) do
  str = gets
  state = 0
  0.upto(str.size-1) do |i|
    if str[i].ord>=48 and str[i].ord<=57
      state+=1 if state%2==0
    else
      state+=1 if state%2==1
    end
  end
  if state==2
    col = nil
    row = nil
    0.upto(str.size-1) do |i|
      if str[i].ord>=48 and str[i].ord<=57
        col = str[0..i-1]
        row = str[i..-1].strip
        break
      end
    end
    coln = 0
    0.upto(col.size-1) do |i|
      coln *= 26
      coln += col[i].ord-64
    end
    puts "R#{row}C#{coln}"
  else
    row = nil
    col = nil
    ci = nil
    0.upto(str.size-1) do |i|
      if str[i].ord == 67
        ci = i
      end
    end
    row = str[1..ci-1]
    col = str[ci+1..-1].to_i
    cols = ""
    while col>0
      cols = (col%26+64).chr + cols
      col /= 26
    end
    puts cols+row
  end
end

n = STDIN.gets
n.to_i.times do |i|
    a = STDIN.gets
    if a =~ /\d+[A-Z]+/
        p "Big format"
        r = a.split(/[A-Z]/)[1]
        c = a.split(/[A-Z]/)[2].to_i
        completeAddress = ""
        while (c > 26)
            completeAddress += ((c/26.0).ceil + 63).chr
            if ((c / 26) < 26)
                c %= 26
            else
                c /= 26
            end

        end
        completeAddress += (c + 64).chr + r
        p completeAddress
    else
        p "Short format"
        c = a[0,a=~/\d/]
        r = a.gsub(/[A-Z]+/,"")
        realrow = 0
        c.bytes.each do |i|
            realrow *= 26
            realrow += (i - 64)
        end
        p "R" + r + "C" + realrow.to_s
    end
end

class SpreadSheets
    def main
        numberOfLines = gets.to_i
        coordinates = Array.new(numberOfLines)

        i = 0
        while i < numberOfLines
            coordinates[i] = gets
            i += 1
        end

        puts convert(coordinates)
    end

    def convert(coordinates)
        result = Array::new
        numericDef = /R(\d+)C(\d+)/
        alphanumericDef = /(\w+)(\d+)/

        coordinates.each do |coordinate|
            if (numericDef.match(coordinate))
                matches = numericDef.match(coordinate)
                row = matches[1]
                column = matches[2]
                convertedColumn = convertNumToAlpha(column.to_i)
                result.push("#{convertedColumn}#{row}")
            elsif (alphanumericDef.match(coordinate))
                matches = alphanumericDef.match(coordinate)
                row = matches[2]
                column = matches[1]
                convertedColumn = convertAlphaToNum(column)
                result.push("R#{row}C#{convertedColumn}")
            end
        end

        return result
    end

    def convertNumToAlpha(num)
        result = String::new

        num -= 1;
        zeroLetter = 'A';
        base26 = 26;
        loop do
            remainder = num % base26;
            result = "#{(zeroLetter.ord + remainder).chr}#{result}"
            num /= base26;
            break if (num == 0)
        end

        return result
    end

    def convertAlphaToNum(alpha)
        result = 1

        zeroLetter = 'A'
        currentExp = 1
        base26 = 26
        alpha.split("").reverse_each do |letter|
            convertedDigit = letter.ord - zeroLetter.ord
            result += convertedDigit * currentExp
            currentExp *= base26
        end

        return result.to_s
    end
end

SpreadSheets::new.main

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num = 0
	digits = [*?A..?Z]

	pow=1
	str.reverse.each_char{|c|
		d = digits.index(c) + 1

		num+=d*pow
		pow*=26
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_36 num
	ans = ""
	digits = [*?A..?Z]

	num=num.to_i
	while num!=0
		ans+=digits[num%26-1]
		num/=26
	end

	ans.reverse
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_36 b}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

r = /R\d+C\d+/
row_regex = /\d+/

n = gets.chomp.to_i

n.times do
   line = gets.chomp
   puts line.match(r)
   if line.match(r)
     row = line[1.. (line =~ /C/)].to_i
     c = line[(line =~ /C/)+1..-1].to_i
     a = 0; b = 0
     a = c
     res = ""
     while (a+26) > 26
        a = c / 26
  			b = c % 26 == 0 ? 26 : c % 26
  			a = c % 26 == 0 ? a - 1 : a
  			c = a
        res.prepend(((b-1) + 65).chr)
     end
     puts "#{res}#{row}"
   else
     num_index = line =~ row_regex
     row = line[num_index..line.length()]
     col = 0
     col_str = line[0..num_index-1]
     col_str.split('').map.with_index  do |chr, i|
       col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))
     end
     puts "R#{row}C#{col}"
   end
end

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if a.include?("R") && a.include?("C") #como el metodo random tiene R&C
			ir=a.index("R") #queremos el index de cada letra
			ic=a.index("C") #porque para q sea random, la diferencia debe ser 1
			return (ic-ir)==1? true : false
		else
			return true
		end
	end
	#revisar
	def convertir(ar)

		case ar.size
		when 3
			num=(ar[0].ord-64)*26*26 +(ar[1].ord-64)*26+(ar[2].ord-64)
		when 2
			num=(ar[0].ord-64)*26 +(ar[1].ord-64)
		when 1
			num=ar[0].ord-64
		else
			num=0
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord<=57 && arr[k].ord>=48) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array)
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end

	#IMPRIMIR RESULTADO
	puts $res

number_of_input=gets.to_i
input_arry=[]
i_a=0

loop do
    break if i_a==number_of_input
    input_arry[i_a]=gets.chomp
    i_a +=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash={}
i_b=0

loop do
    break if i_b==26
    @hash[alph[i_b]]=value[i_b]
    i_b+=1
end

value=(1..26)
alph=('A'..'Z')
value=[*value]
alph=[*alph]
@hash2={}
i_b=0

loop do
    break if i_b==26
    @hash2[alph[i_b]]=value[i_b]
    i_b+=1
end
@hash2['Z']=0

i_c =0

loop do
    break if i_c==input_arry.length
    input1=input_arry[i_c]

    if  input1[0]!='R' || (input1[0]=='R' && input1[1].to_i==0)
        a1=input1
        r=a1[0]
        i=1

        loop do
            break if a1[i].to_i !=0
            r =r + a1[i]
            i+=1
        end

        r1=r.length
        r2=a1.length
        c1= a1[0 .. (r1-1)].reverse
        row= a1[ r1 .. r2].to_i
        c=0
        i=0

        loop do
            break if i==c1.length
            c= c + (@hash[c1[i]]*(26**i))
            i+=1
        end

        puts "R#{row}C#{c}"

    elsif input1[0]=='R' && input1[1].to_i!=0
        k2=input1.split("")

        if k2.index("C")>1
            a1=input1
            r=a1[0]
            i=1

            loop do
                break if a1[i].to_i !=0
                r =r + a1[i]
                i+=1
            end

            r1=r.length
            r2=a1.length
            c1= a1[0 .. (r1-1)].reverse
            row= a1[ r1 .. r2].to_i
            c=0
            i=0

            loop do
                break if i==c1.length
                c= c + (@hash[c1[i]]*(26**i))
                i+=1
            end

            puts "R#{row}C#{c}"
        else
            a1=input1
            s2=a1.split("").map{|s| s}
            r3=3
            s2.find {|i| r3=s2.index(i)+1 if i=='C'}
            i=s2[r3 .. (s2.length - 1)].join.to_i
            row=s2[1 .. (r3-2)].join.to_i
            str_c=""
            loop do
                str_c = str_c + @hash2.key(i%26)
                i=i/26
                break if i==0
            end

            str_c=str_c.reverse
            puts "#{str_c}#{row}"
        end

    end
i_c +=1
end

arr = STDIN.read.split("\n")
n = arr[0].to_i

1.upto(n).each do |i|
  str = arr[i]
  match = str.match(/R([0-9]+)C([0-9]+)/)

  if match
    row = match[2].to_i
    col = match[1]

    r = row
    str = ""
    while(r > 0) do
      val = (r-1) % 26
      str += (val + 65).chr
      r /= 26
    end
    str = str.reverse
    str += col
    puts str
  else
    match = str.match(/([A-Z]+)([0-9]+)/)
    col = match[1]
    row = match[2]

    puts "A"
    s = 0
    rev = col.reverse.split("")
    puts "B"
    rev.each_index do |i|
    puts "rev[i]" + rev[i]
    puts rev[i].ord - 65 + 1
      chr = (rev[i].ord - 65 + 1) * ( 26 ** i )
      puts "chr:#{chr}"
      s += chr
    end

    puts "R#{row}C#{s}"
  end
end

def a_to_n(line)
    length = line.length
    i = 0
    sum = 0
    while i < length
        sum = sum * 26 + (line[i].ord - 'A'.ord + 1)
        i = i + 1
    end
    return sum
end

def n_to_a(line)

    row_str = ""
    row_num = line.to_i
    while row_num > 0
        row_str.prepend( (64 + row_num % 26).chr)
        row_num = row_num/26
    end
    return row_str

end

def xy_to_rc(line)
    col_size = line =~ /[0-9]/

    col_str = line[0...col_size]
    row_str = line[col_size...-1]

    col = a_to_n(col_str)
    row = row_str.to_i

    print("R")
    print(row)
    print("C")
    print(col)

end

def rc_to_xy(line)
    col_size = line =~ /[C]/

    row_str = line[1...col_size]
    col_str = line[col_size+1...-1]

    col = n_to_a(col_str)
    row = row_str.to_i

    print(col)
    print(row)
end

def isrc(line)
    if line[0] == 'R' && line[1] =~ /[0-9]/
        if line[2...-1].include? "C"
            return true
        end
    end
    return false
end

line_count = gets.to_i

while line_count > 0
    line_string = gets
    if isrc(line_string)
        rc_to_xy(line_string)
    else
        xy_to_rc(line_string)
    end
    print("\n")
    line_count = line_count-1
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_letters num
	ans=""
	digs=[*?A..?Z]

	while num!=0
		ans+=digs[num%26 - 1]
		num/=26
	end

	ans.reverse
end

def to_numbers str
	ans=0
	str.reverse!

	pow=0
	str.each_char{|c|
		ans+= (c.ord - 'A'.ord + 1) * 26**pow
		pow+=1
	}

	ans
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R(\d+)C(\d+)/.match line
		puts "#{to_letters $2.to_i}#{$1}"
	else
		p1, p2 = line.scan(/([A-Z]+)([0-9]+)/)[0]
		puts "R#{p2}C#{to_numbers p1}"
	end
}

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

$letters = [""].concat(("A".."Z").to_a)

def rc_ab(rc)
  rc_a = rc.scan(/\d+/)
  rc_a[1] = rc_a[1].to_i
  s = ""

  while(rc_a[1] != 0) do
    s << $letters[rc_a[1] % 26]
    rc_a[1] /= 26
  end

  s = s.reverse << rc_a[0]
  return s
end

def ab_rc(ab)
  ab_c = /[A-Z]+/.match(ab)

  ab_s = ab_c.to_s.reverse
  ab_n = 0

  ab_s.length.times {
    |i|
    ab_n += $letters.index(ab_s[i,1]) * 26 ** i
  }

  s = "R" << ab_n.to_s << "C" << /\d+/.match(ab).to_s
  return s
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  column_index = column.to_s(26).upcase
  column_letters = ''
  column_index.each_char do |c|
    if c.ord > '9'.ord
      column_letters += (c.ord + 9).chr
    else
      if '0' == c
        let = column_letters[column_letters.length - 1]
        column_letters[column_letters.length - 1] = (let.ord - 1).chr
        column_letters += 'Z'
      else
        column_letters += (c.ord + 'A'.ord - '1'.ord).chr
      end
    end
  end

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

n = gets
n = Integer(n)
while n>0
  string = gets
  m = string.size()
  index = 0
  while ('A'..'Z').include? string[index]
    index += 1
  end
  while !(('A'..'Z').include? string[index])
    index += 1
    if index >= m
        break;
    end
  end
  if index == m
    index = 0
    while ('A'..'Z').include? string[index]
      index+=1
    end
    index -= 1
    c = 0
    count = 1
    til = index
    until index < 0
      c += (string[index].unpack("c")[0] - 'A'.unpack("c")[0] + 1) * count
      index -= 1
      count *= 26
    end
    puts "R#{string[til+1..m].chomp}C#{c}"
  else
    index = string.index("C")
    count = Integer(string[index+1..m-2].chomp)
    k = ""
    while count > 0
        k = (count % 26 + 64).chr + k
        count /= 26
    end
    puts "#{k}#{string[1..index-1]}"
  end
  n-=1
end

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  column_letters = ''
  while (column / 26) > 0
    column_letters += ("A".ord - 1 + column / 26).chr
    column -= 26 * (column / 26)
  end
  column_letters += ("A".ord - 1 + column).chr

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num = 0
	digits = [*?A..?Z]

	pow = 0
	str.reverse.each_char{|c|
		d = digits.index(c)+1

		num+=d * 26**pow
		pow+=1
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_27 num
	ans = ""
	digits = [*?A..?Z]

	num = num.to_i
	while num!=0
		ans = digits[num%27] + ans
		num/=27
	end

	ans.reverse
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_27 b}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def to_1var(row, column)

  az = ('A'..'Z').to_a
  azLen = az.length()

  columnAZ = ""
  columnInt = column.to_i

  while columnInt > 0
    columnAZ.insert(0, az[(columnInt % azLen)-1])
    columnInt /= azLen;
  end

  return columnAZ + row

end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
def to_2var(row, column)

  azLen = ('A'..'Z').to_a.length

  columnInt = 0
  column.reverse.each_char.each_with_index { |chr, idx|
    columnInt += (chr.ord - 'A'.ord + 1) * azLen**idx
  }

  return "R#{row}C#{columnInt}"

end

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Main
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

gets.to_i.times {

  coord = gets.strip

  if coord =~ /^R(\d+)C(\d+)$/
    puts to_1var($1, $2)
  elsif coord =~ /^([A-Z]+)(\d+)/
    puts to_2var($2, $1)
  end

}

n=gets.chomp.to_i
data=[]

alpha=['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']
a=0

while a<n
	b=gets.chomp
	data.push(b)
	a+=1
end

osn=26
data.each do |t|
	word=t
	if word[0]=='R'
		flag=false
		for i in(2..word.length-2)
			if word[i]=='C'
				flag=true
			end
		end

		r=[]
		c=[]

		pos=0
		if flag
			for i in(1..word.length-2)
				if word[i]!='C'
					r.push(word[i])
				else
					pos=i
					break
				end
			end
			for i in((pos+1)..word.length-1)
				c.push(word[i])
			end
			rows=r.join.to_i
			cells=c.join.to_i

			cs=[]

			a=0
			while cells>0
				b=cells%osn
				cs.push(alpha[b-1])
				cells-=b
				cells/=osn
			end

			cs.reverse!
			cs.push(rows)

			puts cs.join
		else
			sn=[]
			a=0
			while word[a].to_i==0
				sn.push(word[a])
				a+=1
			end

			number=[]
			for i in(a..word.length-1)
				number.push(word[i])
			end
			numb=number.join.to_i

			sn.reverse!
			rw=0
			for i in(0..sn.length-1)
				rw+=(alpha.index(sn[i])+1)*osn**i
			end

			answer=[]
			answer.push('R')
			answer.push(numb)
			answer.push('C')
			answer.push(rw)
			puts answer.join
		end
	else
		sn=[]
		a=0
		while word[a].to_i==0
			sn.push(word[a])
			a+=1
		end

		number=[]
		for i in(a..word.length-1)
			number.push(word[i])
		end
		numb=number.join.to_i

		sn.reverse!
		rw=0
		for i in(0..sn.length-1)
			rw+=(alpha.index(sn[i])+1)*osn**i
		end

		answer=[]
		answer.push('R')
		answer.push(numb)
		answer.push('C')
		answer.push(rw)
		puts answer.join
	end
end

n = gets
n = Integer(n)
while n>0
  string = gets
  m = string.size()
  index = 0
  while ('A'..'Z').include? string[index]
    index += 1
  end
  while !(('A'..'Z').include? string[index])
    index += 1
    if index >= m
        break;
    end
  end
  if index == m
    index = 0
    while ('A'..'Z').include? string[index]
      index+=1
    end
    index -= 1
    c = 0
    count = 1
    til = index
    until index < 0
      c += (string[index].unpack("c")[0] - 'A'.unpack("c")[0] + 1) * count
      index -= 1
      count *= 26
    end
    puts "R#{string[til+1..m].chomp}C#{c}"
  else
    index = string.index("C")
    count = Integer(string[index+1..m-2].chomp)
    k = ""
    while count > 0
        if count % 26 == 0
          k = "Z" + k
          count /= 26
          count -= 1
        end
        if count>0
          k = (count % 26 + 64).chr + k
          count /= 26
        end
    end
    puts "#{k}#{string[1..index-1]}"
  end
  n-=1
end

num = gets.chomp.to_i
puts num
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num / 26
            col_num %= 26
            col_str += (this_char+64).chr
        end
        col_str += (col_num+65).chr
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

arr = STDIN.read.split("\n")
n = arr[0].to_i

1.upto(n).each do |i|
  str = arr[i]
  match = str.match(/R([0-9]+)C([0-9]+)/)

  if match
    row = match[2].to_i
    col = match[1]

    r = row
    str = ""
    while(r > 0) do
      val = (r-1) % 26
      str += (val + 65).chr
      r /= 26
    end
    str = str.reverse
    str += col
    puts str
  else
    match = str.match(/([A-Z]+)([0-9]+)/)
    col = match[1]
    row = match[2]

    s = 0
    col.reverse.split("").each_index do |i|
      chr = (col[i].ord - 65) * (26**i) + 1
      s += chr
    end
    puts "R#{row}C#{s}"
  end
end

$letters = [""].concat(("A".."Z").to_a)

def rc_ab(rc)
  rc_a = rc.scan(/\d+/)
  rc_a[1] = rc_a[1].to_i
  s = ""

  while(rc_a[1] != 0) do
    s << $letters[rc_a[1] % 26]
    rc_a[1] /= 26
  end

  s = s.reverse << rc_a[0]
  return s
end

def ab_rc(ab)
  ab_c = /[A-Z]+/.match(ab)

  ab_s = ab_c.to_s.reverse
  ab_n = 0

  ab_s.length.times {
    |i|
    ab_n += $letters.index(ab_s[i,1]) * 26 ** i
  }

  s = "R" << /\d+/.match(ab).to_s << "C" << ab_n.to_s
  return s
end

n = gets().chomp.to_i
a = []
n.times {
|i|
  a[i] = gets().chomp()
}
a.each{
|i|
  if (/^R\d+C\d+$/ =~ i) then
    #RXCY
    puts(rc_ab(i))
  else
  #AB23
    puts(ab_rc(i))
  end
}

n=gets.chomp.to_i
n.times {
	s=gets.chomp.to_s
	s.scan(/^R([0-9]+)C([0-9]+)$/)
	unless !$~
		r=$~[1].to_i
		c=$~[2].to_i
		remainder=c%26
		g=(remainder+64).chr
		while remainder !=c
			c-=remainder
			c/=26
			remainder=c%26
			g+=(remainder+64).chr
		end
		print(g.reverse)
		puts (r)
		next
	end
	s.scan(/^([A-Z]+)([0-9]+)$/)
	unless !$~
		c=$~[1]
		r=$~[2].to_i
		k=1
		sum=0
		c=c.reverse
		c=c.split("")
		for i in c
			#puts (i)
			hold=(i.getbyte(0)-64)*k
			#puts ("hold = #{hold}")
			sum+=hold
			k*=26
		end
		puts ("R#{r}C#{sum}")
	end

}

#!/usr/bin/env ruby

def i2c
end

def c2i
end

def convert(str)
  if str =~ /^R(\d+)C(\d+)$/
    rows, cols  = $1.to_i, $2.to_i
    a = []
    loop do
      a.unshift cols % 26
      cols /= 26
      break if cols == 0
    end
    "#{a.map{|i| (i + 64).chr}.join}#{rows}"
  elsif str =~ /^([A-Z]+)(\d+)$/
    cols = 0
    $1.size.times do |i|
      cols += ($1.unpack('C*')[-i - 1] - 64) * (26 ** i)
    end
    "R#{$2}C#{cols}"
  else
    "invalid arg"
  end
end

n = gets.to_i
lines = []
n.times do
  lines << convert(gets.chomp)
end

lines.each{|s| puts s}

r = /R\d+C\d+/
row_regex = /\d+/

n = gets.chomp.to_i

n.times do
   line = gets.chomp
   puts line.match(r)
   if line.match(r)
     row = line[1.. (line =~ /C/)].to_i
     c = line[(line =~ /C/)+1..-1].to_i
     a = 0; b = 0
     a = c
     res = ""
     while (a+26) > 26
        a = c / 26
  			b = c % 26 == 0 ? 26 : c % 26
  			a = c % 26 == 0 ? a - 1 : a
  			c = a
        res.prepend(((b-1) + 65).chr)
     end
     puts "#{res}#{row}"
   else
     num_index = line =~ row_regex
     row = line[num_index..line.length()]
     col = 0
     col_str = line[0..num_index-1]
     col_str.split('').map.with_index  do |chr, i|
       col += (chr.ord - 'A'.ord + 1) * (26 ** (num_index-1-i))
     end
     puts "R#{row}C#{col}"
   end
end

$table = ["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 to_E(x)
    b = ""
    t = true
    while x > 26 do
        if x % 26 == 0 then
            str = to_E(x-1)
            str[-1] = "Z"
            b = str + b
            x = 0
            t = false
        else
            b = $table[(x % 26) - 1] + b
            x /= 26
        end
    end
    if t then
        b = $table[x-1] + b
    end
    return b
end

def to_T(x)
    str = x.gsub(/[0123456789]/, "*")
    k = str.index("*")
    str1 = str[0...k]
    r = 0
    q = 26
    n = str1.size
    n.times do |i|
        r += ($table.index(str1[i]) + 1)*q**(n-i-1)
#       p (n-i-1)
#       p $table.index(str1[i]) + 1
#       p r
    end
    result = "R" + x[k..-1] + "C" + r.to_s
    return result
end

n = gets.to_i
ind = []
outd = []
n.times do |i|
    ind[i] = gets.chomp
    r = ind[i].index("R")
    c = ind[i].index("C")
    str = ind[i].gsub(/[ABDEFGHIJKLMNOPQSTUVWXYZ]/, "*")
    k = str.index("*")
    if r && c && !k then
        ind[i] = to_E(ind[i][c+1..-1].to_i) + ind[i][r+1...c]
    else
        ind[i] = to_T(ind[i])
    end
end
n.times do |i|
    puts "#{ind[i]}"
end

def excel_to_index(number)
  row = number.gsub(/[a-zA-Z]/, '').chomp
  column = number.gsub(/\d/, '').chomp

  length = column.length
  column_index = 0
  column.each_char do |c|
    column_index += (c.ord - 'A'.ord + 1) * (26 ** (length - 1))
    length -= 1
  end

  'R' + row + 'C' + column_index.to_s
end

def index_to_excel(number)
  row, column = number.sub(/R/, '').split(/C/).map(&:to_i)

  result = []
  begin
    x = column % 26
    x = 26 if 0 == x
    column = (column - x) / 26

    result.push x
    puts column
  end while column > 0

  column_letters = ''
  result.reverse_each { |e|
    column_letters += (e.ord + 'A'.ord - 1).chr
  }

  column_letters + row.to_s
end

count = gets.to_i

count.times do
  num = gets.upcase
  if num[/R\d+C\d+/]
    puts index_to_excel num
  else
    puts excel_to_index num
  end
end

#!/usr/bin/ruby
def fromcell(s)
  r=0
  s.length.times{|i|
    #r=r*26+s[i]-64
  }
  return r
end

def tocell(n)
  r=""
  while n>0 do
    r=(n%26+64).chr+r
    n/=26
  end
  return r
end

n=gets.chomp.to_i
n.times{|z|
  s=gets.chomp
  if s=~/^([A-Z]+)(\d+)$/ then
puts "R"
#+$2.to_s+"C"+fromcell($1).to_s
end
  if s=~/R(\d+)C(\d+)/ then puts tocell($2.to_i)+$1.to_s end
}
exit(0)

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if (a.include?("R") && a.include?("C")) #como el metodo random tiene R&C
			ir=a.index("R")
			ic=a.index("C")

			if a.index("R")==0
				if a.index("C")==1
					if (a[2].ord>=48 && a[2].ord<=57)
						return true
					else
						return false
					end
				else
					num_char=0
					0.upto(a.size-1) do |j|
						if (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str
							num_char+=0
						else
							num_char+=1
						end
					end
				end

				return num_char==2? false : true
			else
				return true
			end
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array) #TRUE ES excel
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end
	#IMPRIMIR RESULTADO
	puts $res

n = gets.to_i
n.times do
  s = gets
  m = /R(\d+)C(\d+)/.match(s)
  if m != nil
    val = m[2].to_i
    col = ""
    while val > 0
      col.concat((val % 26 + 65 - 1).chr)
      val /= 26
    end
    col.reverse!
    puts "#{col}#{m[1]}"
  else
    m = /([A-Z]+)(\d+)/.match(s)
    col = m[1]
    col.reverse!
    cnt, base = 0, 1
    col.length.times do |i|
      cnt += (col[i].ord - 'A'.ord + 1) * base
      base *= 26
    end
    puts "R#{m[2]}C#{cnt}"
  end
end

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
        num = 0
        digits = [*?A..?Z]

        pow=1
        str.reverse.each_char{|c|
                d = digits.index(c) + 1

                num+=d*pow
                pow*=26
        }

        num
end

def to_first line
        letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
        "R#{number}C#{to_number letters}"
end

def to_27 num
        ans = ""
        digits = [*?A..?Z]

        num = num.to_i
        while num!=0
                ans+=digits[num%27 - 1]
                num/=27
        end

        ans.reverse
end

def to_second line
        a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
        "#{to_27 b}#{a}"
end

n=gets.to_i

n.times{
        line=gets.strip

        if /R([0-9]+)C([0-9]+)/.match line
                puts to_second line
        else
                puts to_first line
        end
}

num = gets.chomp.to_i
num.times do
    old = gets.chomp
    results = old.match('R(\d+)C(\d+)')
    if results != nil
        col_num = results[2].to_i
        base = 1;
        col_str = ""
        while col_num > 26
            this_char = col_num % 26
            col_num /= 26
            if this_char == 0
                this_char = 26
            end
            col_num -= 1
            col_str = "#{(this_char+64).chr}#{col_str}"
        end
        col_str = "#{(col_num+64).chr}#{col_str}"
        puts "#{col_str}#{results[1]}"
    else
        results = old.match('([A-Z]+)(\d+)')
        col_str = results[1]
        base = 26**(col_str.length-1)
        col_num = 0
        col_str.each_char do |c|
            col_num += (c.ord-64)*base
            base /= 26
        end
        puts "R#{results[2]}C#{col_num}"
    end
end

def main
	tc=gets.chomp.to_i;
	alp=[*'A'..'Z'];
	hs={}
	i=1;
	alp.each do |z|
		hs[z]=i;
		i+=1;
	end
	for i in 1..tc
		s=gets.chomp.to_s;
		if s.count("R")==1 and s.count("C")==1
			indc=s.index("C");
			col=s[indc+1...(s.length)].to_i;
			j=1;
			while(26*j+1<col)
				j+=1;
			end
			j=j-1;
			val=26*j+1;
			c1=alp[j-1];
			scv=col-val;
			c2=alp[scv];
			puts "%s%s%s" %[c1,c2,s[1...indc]];
		else
			sr=s;
			sr=sr.reverse();j=0;val=0;
			for x in 0...(sr.length())
				c=sr[x].chr;
				if alp.include?(c)
					if j==0
						val=val+hs[c];
						j=1;
					else
						val=val+(26*hs[c]);
					end
				end
			end
			x=0;
			for x in 0...(s.length)
				if alp.include?(s[x].chr)
					next;
				else
					break
				end
			end
			puts "R%sC%d" %[s[(x)...(s.length)],val];
		end

	end
end
main

#=================================
# Better be sure than sorry.
#=================================
$stdin = File.open("./input.txt", "r") if ENV["LOGNAME"]=="skydos"
#=================================

def to_number str
	num=0
	digs=[*?A..?Z]

	pow=0
	str.reverse.split(//).each{|c|
		num+= 26**pow * (digs.index(c) + 1)
		pow+=1
	}

	num
end

def to_first line
	letters, number = line.scan(/([A-Z]+)([0-9]+)/)[0]
	"R#{number}C#{to_number letters}"
end

def to_27 num
	str = ""
	digs = [*?A..?Z]

	while num!=0
		str+=digs[num%26-1]
		num/=26
	end

	str.reverse
end

def to_second line
	a, b = line.scan(/R([0-9]+)C([0-9]+)/)[0]
	"#{to_27 b.to_i}#{a}"
end

n=gets.to_i

n.times{
	line=gets.strip

	if /R([0-9]+)C([0-9]+)/.match line
		puts to_second line
	else
		puts to_first line
	end
}

require 'scanf'
n = STDIN.gets.scanf('%d').first
while n>0
  l = STDIN.gets.chop
  row = nil
  col = nil
  /R(?<row>\d+)C(?<col>\d+)/=~l
  unless (row and col)
    /(?<col>[A-Z]+)(?<row>\d+)/=~l
    col_ = 0
    i=0
    col.each_byte do |a|
      pos = col.length - i - 1
      col_+=('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)**pos*(a-'A'.bytes.to_a.first+1)
      i+=1
    end
    row = row.to_i
    puts "R"+row.to_s+"C"+col_.to_s
  else
    col = col.to_i
    col_ = ''
    while col!=0
      temp = col % ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)
      col_+=['A'.bytes.to_a.first+temp-1].pack("U")
      col /= ('Z'.bytes.to_a.first-'A'.bytes.to_a.first+1)
    end
    col_.reverse!
    puts col_+row
  end
  n-=1
end

	#recibiendo el numero de iteraciones
	input=gets.chomp
	n=input.to_i
	#metodo para saber si la cadena es excel o random
	def validar_excel(a)
		if (a.include?("R") && a.include?("C")) #como el metodo random tiene R&C
			if a.index("R")==0
				num_char=0
				0.upto(a.size-1) do |j|
					if (a[j].ord>=48 && a[j].ord<=57) #ASCII para diferenciar num & str
						num_char+=0
					else
						num_char+=1
					end
				end

				return num_char==2? false : true
			else
				return true
			end
		else
			return true
		end
	end
	#revisar
	def convertir(ar)
		n=ar.size-1
		i=0
		num=0

		loop do
			if n<0
				break
			end

			num=num+(ar[i].ord-64)*(26**n)
			n-=1
			i+=1
		end

		return num
	end

	#primer metodo de BC23 a R23C55
	def excel_to_random(arr)
		parte_num=""
		parte_str=""

		0.upto(arr.size-1) do |k|
			if (arr[k].ord>=48 && arr[k].ord<=57) #ASCII para diferenciar num & str
				parte_num=parte_num+arr[k]
			else
				parte_str=parte_str+arr[k]
			end
		end

		parte_c=convertir(parte_str)
		random="R"+parte_num+"C"+"#{parte_c}" #creando el random

		return random
	end

	#metodo divisiones sucesivas?
	def divsuc(num)
		num_car=26
		pivot=num
		ndig=0
		arreglo_num=[]
		potencia=1

		loop do
			pivot=pivot-26**potencia
			ndig+=1
			potencia+=1
			if pivot<=0
				break
			end
		end

		#real deal
		loop do
			if num==0
				break
			end
			if num%num_car !=0
				arreglo_num[ndig-1]=((num%num_car)+64).chr()
				num=num/num_car
			else #COMPORTAMIENTO DIFERENTE CUANDO EL num ES MULTIPLE DE 26 !! (2 days!)
				q=num/num_car
				num=q-1
				arreglo_num[ndig-1]=(num_car+64).chr()
			end
			ndig-=1
		end
		return arreglo_num
	end

	#segundo metodo de R23C55 a BC23
	def random_to_excel(arr)
		row=""
		col=""
		a=0

		1.upto(arr.size-1) do |k|
			(arr[k]=="C")? a+=1:a+=0

			if a==0
				row=row+arr[k]
			else
				if (arr[k]!="C")
					col=col+arr[k]
				end
			end
		end
		col=col.to_i
		cole=divsuc(col)#convertir la columna a excel
		excel=cole.join+row

		return excel
	end

	$res=[] #definición de la variable GLOBAL, para poder imprimirlo después

	0.upto(n-1) do |j|
		cadena=gets.chomp.upcase
		array=cadena.split("")
		i=validar_excel(array)

		if i
			resultado=excel_to_random(array) #TRUE ES excel
		else
			resultado=random_to_excel(array)
		end

		$res[j]=resultado 	#recordar que el puts imprime con /n y el print no lo hace
	end
	#IMPRIMIR RESULTADO
	puts $res

n = gets().to_i
for i in 1..n
	line = gets().split(/(\d+)/)
	if line[0] == 'R'
		col = line[3].to_i
		for j in 1..100
			break if 26**j >= col
			col -= 26**j
		end
		s = (col-1).to_s(26).rjust(j,'0').tr('0123456789abcdefghijklmnop', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
		puts s << line[1]
	else
		row = line[1]
		ans = 1 + line[0].tr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789abcdefghijklmnop').to_i(26)
		for j in 1..line[0].length-1
			ans += 26**j
		end
		puts 'R' << row << 'C' << ans.to_s
	end
end