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.

<?php

$stdin = fopen('php://stdin', 'r');

fscanf($stdin, "%d", $n);

$results = array();
for($i = 0; $i < $n; $i++)
{
	 fscanf($stdin, "%s", $str);
	 $results[] = $str;
}

$baseNum = 26;
$baseChar = ord('A') - 1;

for($i = 0; $i < $n; $i++)
{
	$str = $results[$i];

	$matches = array();

	$res = '';

	if(preg_match('/R(\d+)C(\d+)/', $str, $matches))
	{
		$num = $matches[2];

		while($num > $baseNum)
		{
			$left = $num % $baseNum;
			$num  = intval($num  / $baseNum);
			if(!$left)
			{
				$left = 26;
				$num--;
			}

			$res = chr($left + $baseChar) . $res;

		}

		if($num)
		{
			$res = chr($num + $baseChar) . $res;
		}

		$res .= $matches[1];

		echo $res . PHP_EOL;
	}
	else
	{
		preg_match('/([A-Z]+)(\d+)/', $str, $matches);

		$res = 'R' . $matches[2] . 'C';

		$str = str_split($matches[1]);
		$pos = count($str) - 1;
		$sum = 0;
		foreach($str as $chr)
		{
			$sum += (ord($chr) - $baseChar) * pow($baseNum, $pos);
			$pos--;
		}

		echo $res . $sum . PHP_EOL;

	}
}

<?php
    fscanf(STDIN, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf(STDIN, "%s\n", $coords);
        $coords = str_split($coords);
        $letters = array();
        $digits = array();
        $RXCY = 0;
        while (count($coords)) {
            $char = array_shift($coords);
            if (is_numeric($char)) {
                $digits[$RXCY] .= $char;
            } elseif(isset($digits[0]) && !$RXCY) {
                $RXCY = 1;
                $letters[$RXCY] .= $char;
            } else {
                $letters[$RXCY] .= $char;
            }
        }

        if ($RXCY) {
            $col = $digits[1];
            $colCode = '';
            while ($col > 26) {
                $letNum = $col % 26;
                if ($letNum == 0) {
                    $letNum = 26;
                    $col = $col / 26 - 1;
                } else {
                    $col = floor($col / 26);
                }
                $colCode = chr(64 + $letNum) . $colCode;
            }
            if ($col > 0) {
                $colCode = chr(64 + $col) . $colCode;
            }
            $resultCode = $colCode . $digits[0];
        } else {
            $colArray = str_split($letters[0]);
            $colNum = 0;
            $power = 0;
            while ($let = array_pop($colArray)) {
                $colNum += (ord($let) - 64) * pow(26, $power++);
            }
            $resultCode = 'R' . $digits[0] . 'C' . $colNum;
        }
        echo "$resultCode\n";
    }
?>

<?php
$n = readline();
$spreadSheetArray = [];
for ($i = 0; $i < $n; $i++){
    $temp = readline();
    array_push($spreadSheetArray, $temp);
}

for ($i = 0; $i < count($spreadSheetArray); $i++){
    if (isRCNotation($spreadSheetArray[$i])){
        convertToNormal($spreadSheetArray[$i]);
    }
    else{
        convertToRC($spreadSheetArray[$i]);
    }
}

function isRCNotation($value){
    $numberReached = false;
    $RCNotation = false;
    $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

    for ($i = 0; $i < strlen($value); $i++){
        if (in_array($value[$i], $digits)){
            $numberReached = true;
        }
        if ($numberReached){
            if (!in_array($value[$i], $digits)){
                $RCNotation = true;
                break;
            }
        }
    }

    return $RCNotation;
}

function convertToNormal($word){
    $normal = "";
    $indexes = array();
    $alphabet = ['Z', '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'];

    $posR = strpos($word, 'R');
    $posC = strpos($word, 'C');

    $row = substr($word, $posR + 1, $posC-1);
    $col = substr($word, $posC + 1);

    if($col <= 25){
        $remainder = $col % 26;
        array_push($indexes, $remainder);
    }
    else{
        while($col > 25){
            $remainder = $col % 26;
            array_push($indexes, $remainder);
            if($remainder == 0){
                $col = ($col / 26) -1;
                if($col == 0){
                    break;
                }
            }
            else{
                $col = $col / 26;
            }
            if ($col / 26 < 25){
                $col = floor($col);
                array_push($indexes, $col);
            }
        }
    }

    $rereversedIndexes = array_reverse($indexes);
    for ($i = 0; $i < sizeof($indexes); $i++){
        $normal = $normal.$alphabet[$rereversedIndexes[$i]];
    }

    print($normal.$row."\n");
}

function convertToRC($word){
    $rowNum = 0;

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

    for ($i = 0; $i < strlen($word); $i++){
        if(in_array($word[$i], $digits)){
            $index = $i;
            break;
        }
    }

    $rowRev = substr($word, 0, $index);
    $col = substr($word, $index);

    $row = strrev($rowRev);

    for($i = strlen($row)-1; $i >= 0; $i--){
        $rowNum += $alphabet[$row[$i]] * pow(26, $i);
    }

    print("R".$col."C".$rowNum."\n");
}

<?php
/*
In the popular spreadsheets systems (for example, in Excel) the following numeration of
columns is used. The first column has number A, the second — number B, etc. till column
26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB,
column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation
of the column and the row numbers. For example, BC23 is the name for the cell that is in
column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
showing the column and the row numbers respectfully. For instance, R23C55 is the cell
from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and
produce each item written according to the rules of another numeration system.

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

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

Sample test(s)
Input
2
R23C55
BC23

Output
BC23
R23C55
*/
$n = fgets(STDIN);
for ($i = 0; $i < $n; $i++)
    $r[$i] = fgets(STDIN);

/*
$n = 2;
$r[0] = 'BDWET1000000';
$r[1] = 'R1000000C999954';
print_r($r);
*/
for ($i = 0; $i < $n; $i++) {
    if (preg_match('"[R][0-9]{1,9}[C][0-9]{1,9}"',$r[$i]) == 1) {
        $s = preg_split('"[RC]"',$r[$i]);

        $s2 = intval($s[2]);
        $d1 = '';
        //echo "$s2\n";
        while ($s2 > 0) {
            $d1 = chr(($s2 - 1) % 26 + 65) . $d1;
            //echo "--$s2 $d1\n";
            $s2 = floor(($s2 - 1) / 26);
        }
        echo "$d1$s[1]\n";
        //print_r ($s);
    }
    else {
        $l = preg_split('"[0-9]"',$r[$i]);
        $d = preg_split('"[A-Z]"',$r[$i]);

        $l1 = str_split($l[0]);
        $re = 0;
        for ($j = 0; $j < count($l1); $j++) {
            $re = 26 * $re + ord($l1[$j]) - 64;
            //echo "$j $re\n";
        }
        $d1 = intval($d[count($d) - 1]);
        //print_r($l1);
        //print_r($d);
        echo "R$d1" . "C$re\n";
    }
}
?>

<?php
$inp = fopen("php://stdin", 'r');
$str = stream_get_contents($inp);
$params = explode("\r\n", $str);

$n = $params[0];
$cells = array_slice($params, 1);
$letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$patternRC = '/R([\d]+)C([\d]+)/';
$patternA1 = '/([A-Z]+)([0-9]+)/';

foreach($cells as $cell){
    if(preg_match($patternRC, $cell, $matches)){
        $r = $matches[1];
        $c = $matches[2];
        echo num2alpha($c, $letters).$r.PHP_EOL;
    } else if  (preg_match($patternA1, $cell, $matches)){
        $r = $matches[2];
        $c = $matches[1];
        echo "R".$r."C".alpha2num($c, $letters).PHP_EOL;
    }
}

function num2alpha($n, $letters){
    $c = '';

    for($i = $n; $i > 0; $i = floor($i / 26)){
        $k = ($i % 26);
        if($k == 0){
            $k = 26;
            $i--;
        }
        $c = $letters[$k-1].$c;
    }

    return $c;
}

function alpha2num($n, $letters){
    $c = 0;

    for($i = strlen($n), $j = 0; $i > 0;$i--,$j++){
        $k = array_search($n[$i-1], $letters) + 1;
        if($j > 0){
            $k = $k * pow(26, $j);
        }
        $c = $k + $c;
    }

    return $c;
}

?>

<?php

$n = 0;

fscanf(STDIN, "%d", $n);

for ($iv = 0; $iv < $n; $iv++) {
    fscanf(STDIN, "%s", $var);

    if(preg_match("/R([0-9]+)C([0-9]+)/", $var, $matches)){
        $new = "";
        mytostr((int)$matches[2], $new);
        print $new.$matches[1]."\n";
    }
    elseif ( preg_match("/([A-Z]+)([0-9]+)/", $var, $matches) ) {
        $new = 0;
        mytoint($matches[1], $new);
        print "R".$matches[2]."C".$new."\n";
    }
}

function mytostr($param, &$result) {
    $result = "";

    while($param >= 1)
    {
        $t = $param % 26;
        if($t == 0 ) $t = 26;
        $result = chr($t + ord("A") - 1) . $result;
        $param = floor($param / 26) ;
        if($t == 26 ) $param -= 1;
    }

    //R98C688
    //R90C35
    //R228C494
}

function mytoint($param, &$result) {
    $result = 0;
    for ($index = 0; $index < strlen($param); $index++) {
        $result += (ord($param[$index]) - ord("A") + 1) * pow(26, (strlen($param) - $index - 1));
    }
}

?>

<?php

    function get_stdin_vars($str, $count) {
        $str =(string) $str;
        $count =(int) $count;
        $vars = array(); // for result
        $var_index = 0; // index of array vars
        $str_index = 0; // index of symbol in $str
        while($var_index <= $count) {
            while ($str_index<strlen($str)) {
                if($str[$str_index] != ' ' and $str[$str_index] != "\r") {
                    $vars[$var_index] .= $str[$str_index];
                }
                else {
                    if ($vars[$var_index] != '') {
                       $str_index++;
                       break;
                    }
                }
                $str_index++;
            }
            $var_index++;
        }
        return $vars;
    }

    function get_assocc_char($num) {
        global $alphabet;
        $num = (int) $num;
        $result = $num/26;
        $rest = $num%26;
        if($result > 1) {
            if($rest == 0) {
                return get_assocc_char((int) ($result-1)).$alphabet[26];
            }
            else {
                return get_assocc_char((int) ($result)).$alphabet[$rest];
            }
        }
        else {
            if($rest == 0) {
                return $alphabet[26];
            }
            else {
                return $alphabet[$rest];
            }
        }
    }

    function convert($str) {
        global $alphabet;
        $matches = array();
        if (preg_match('#^R([0-9]+)C([0-9]+)$#',$str,$matches)==1) {
            $row = $matches[1];
            $col = get_assocc_char($matches[2]);
            return $col.$row;
        }
        elseif(preg_match('#^([A-Z]+)([0-9]+)$#',$str,$matches)==1) {
            $row = $matches[2];
            $col = $matches[1];
            $colnum = 0;
            $col_length = strlen($col);
            $base = 1;
            for($i=$col_length-1;$i>=0;$i--) {
                if($i != $col_length-1) { $base = $base * 26; };
                $colnum = $colnum + $base * $alphabet[$col[$i]];
            }
            return 'R'.$row.'C'.$colnum;
        }
        else { die("Error: ".$str." - unknown pattern\n"); }
    }

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

    $alphabet = array (1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M',
            14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z',
            'A'=>1,'B'=>2,'C'=>3,'D'=>4,'E'=>5,'F'=>6,'G'=>7,'H'=>8,'I'=>9,'J'=>10,'K'=>11,'L'=>12,'M'=>13,
            'N'=>14,'O'=>15,'P'=>16,'Q'=>17,'R'=>18,'S'=>19,'T'=>20,'U'=>21,'V'=>22,'W'=>23,'X'=>24,'Y'=>25,'Z'=>26);
    $count = get_stdin_vars(fgets(STDIN),1);
    $count = (int)$count[0];

    if($count<1 or $count>100000) {
        die('Error: number of elements must be in range 1-100000');
    }

    for ($i=0;$i<$count;$i++) {
        $indication = get_stdin_vars(fgets(STDIN),1);
        $indication = $indication[0];
        echo convert($indication)."\n";
    }
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/R([0-9]+)C([0-9]+)/", $line, $matches) == 1) {
		fprintf($fw, numToChar($matches[2]).$matches[1].PHP_EOL);
	} elseif (preg_match("/([A-Z]+)([0-9]+)/", $line, $matches) == 1) {
		fprintf($fw, 'R'.$matches[2].'C'.charToNum($matches[1]).PHP_EOL);
	}
}
?>

<?php
error_reporting(0);
$char_array=array();
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$text = explode("\n",$datatxt);
unset($text[0]);
 // $text=array('RC593');
for($i=65;$i<91;$i++){
$char_array[chr($i)]=$i-64;
$char_array2[$i-64]=chr($i);
}
// var_dump($char_array2);die();
foreach($text as $key => $str) {
if (strlen($str)>0){
if (preg_match("/R[0-9]+C[0-9]+/",$str)) {
sscanf($str,"R%dC%d",$row,$col);
echo number_column($col).$row;
} else {
preg_match("/([A-Z]*)(\\d+)/", $str, $matches);
echo "R".$matches[2]."C".return_column($matches[1]);
}
if ($key!=count($text)){
echo "\n";
}
}
}
function return_column($str) {
global $char_array;
$result = 0;
$ab = 1;
for($i=strlen($str);$i>0;$i--) {
$result+=$char_array[$str[$i-1]]*$ab;
$ab*=26;
}
return $result;
}
function number_column($str) {
global $char_array2;
$result = "";
$result2="";
$a = $str;
while($a>0) {
$letter = $a %26;
$a = ($a - $letter)/26;
if ($letter!=0){
$result .= $char_array2[$letter];
} else {
$result.="Z";
$a--;
}
}
for ($i=strlen($result);$i>0;$i--) {
$result2.=$result[$i-1];
}

return $result2;
}
?>

<?php
function read_sheet($str) {
    if (preg_match("/R(\d+)C(\d+)/",$str,$match)) {
        $sub = $match[2];
        while ($sub > 0) {
            $mod[] = bcmod($sub,26);
            $sub = bcdiv($sub,26);
        }

        $count = count($mod);
        $column = '';
        $tmp = [];
        for ($i =0;$i< $count;$i++) {
            $now = $mod[$i];
            if ($mod[$i] == 0) {
                $tmp[$i] = true;
                $now = 26;
            }

            if ($tmp !== null and $tmp[$i-1]) {
                if ($now == 0){
                    $now = 26;
                }
                $now = bcsub($now,1);
                if ($now < 0) {
                    $now = 26 + $now;
                }
                if ($now == 0) {
                    $now = 26;
                    $tmp[$i] = true;
                    if ($i == $count -1) continue;
                };
            }

            $column .= chr($now+64);
        }
        $column = strrev($column);
        return $column.$match[1];

    } elseif (preg_match("/([A-Z]+)(\d+)/",$str,$match)) {
        $len = strlen($match[1]);
        $num = 0;       // 字母序列和
        for ($i = 0; $i < $len; $i++) {
            $num = bcadd(bcmul(bcsub(ord($match[1][$i]),64),bcpow(26,bcsub($len,bcadd($i,1)))),$num);
        }
        return "R".$match[2]."C".$num;
    }
}

$line = 0;
while ($data = fscanf(STDIN,"%s")) {
    if (!$line) {
        $line++;
        continue;
    }
    echo read_sheet($data[0]);
    echo "\n";
}

<?php

    $stdin = fopen('php://stdin', 'r');;
    $count = trim(fgets($stdin));
    $data = '';
    for($i = 0;$i<$count;$i++)
    {
        $data .= fgets($stdin);
    }
    $arr = explode("\r\n", $data);
    $pattern1 = '/R(\d+)C(\d+)/i';
    $pattern2 = '/([A-Z]+)(\d+)/i';
    for($i = 0;$i<$count;$i++)
    {
       if(preg_match($pattern1, $arr[$i]))
       {
           echo convert_1($arr[$i])."\n";
       }
       else if(preg_match($pattern2, $arr[$i]))
       {
          echo convert_2($arr[$i])."\n";
       }
    }

function convert_1($string)
{
    preg_match('/(\d+)[C](\d+)/i', $string, $matches);
    $first = $matches[1];
    $second = $matches[2];
    $res='';
    while ($second > 0)
    {
            $res = chr(($second - 1) % 26 + 65) . $res;
            $second = floor(($second - 1) / 26);
     }
    return $res.$first;
}

function convert_2($string)
{
    preg_match('/([A-Z]+)/i', $string, $matches);
    $first = $matches[0];
    preg_match('/(\d+)/i', $string, $matches);
    $second = $matches[0];
    $res='';
    for($i = 0; $i<strlen($first);$i++)
    {
       $res += (ord($first[$i]) - ord("A") + 1) * pow(26, (strlen($first) - $i - 1));
    }
    return "R".$second."C".$res;

}

<?php

function toAlpha($num){
        $res="";
        while ($num>0)
        {
                $r=($num-1)%26;
                $res = chr($r+65).$res;
                $num = floor(($num-1)/26);
        }
        return $res;
}

function toNum($string){
        $int = 0;
        $len = strlen($string);
        for($i = 0; $i< $len; $i++){
                $int*=26;
                $int += ord($string[$i]) - 64;
        }
        return $int;
}

$file = fscanf(STDIN, "%d\n", $cells);
for($i=0; $i<$cells; $i++){
        fscanf(STDIN, "%s\n", $line);
        if($line[0] == 'R' && ord($line[1])>=48&&ord($line[1])<=57){
                $cPos = strpos($line, 'C', 2);
                if($cPos !== false){
                        print(toAlpha(substr($line, $cPos+1)).substr($line, 1, $cPos-1)."\n");
                }else{
                        print('R'.substr($line, 1)."C18\n");
                }
        }else{
                preg_match('/[0-9]/', $line, $matches, PREG_OFFSET_CAPTURE);
                print('R'.substr($line, $matches[0][1]).'C'.toNum(substr($line, 0, $matches[0][1]))."\n");
        }
}

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%s", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$d = $a % 26;
		$a = floor($a / 26);
		if ($d == 0) {
			$d += 26;
			$a--;
		}
		$result .= chr(64 + $d);

	}
	return strrev($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "\n";
}
echo change($a[$n - 1]);

<?php
fscanf(STDIN,"%d",$n);
function IsInt($var)
{
  if(ord($var)>=48&&ord($var)<=57)
    return true;
  else
    return false;
}
function IsType1($var)
{
  $res=false;;
  for($i=1;$i<strlen($var);$i++)
  {
    if('C'==($var[$i]))
    {
      $res=true;
      break;
    }
  }
  return $res;
}
function GetInt($var)
{
  $res="";
  for($i=1;$i<strlen($var);$i++)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return $res;
    }
  }
}
function GetInt_D($var)
{
  $res="";
  for($i=strlen($var)-1;$i>=0;$i--)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return strrev($res);
    }
  }
}

function conversion_int($var)
{
  $res="";
  while($var>26)
  {
    if($var%26!=0)
    {
    $res.=chr(64+$var%26);
    $var=($var-$var%26)/26;
    }
    else {
      $res.='Z';
      $var=($var)/26-1;
    }
  }
  if($var!=0)
  $res.=chr(64+$var);
  return strrev($res);
}
function conversion_str($var)
{
  $res=0;
  for($i=strlen($var)-1;$i>=0;$i--)
  {
    $temp=1;
    for($j=strlen($var)-1;$j>$i;$j--)
    {
      $temp*=26;
    }
    if($var[$i]!='Z')
    $res+=(ord($var[$i])-64)*$temp;
    else {
      $res+=$temp*26;
    }
  }
  return $res;
}
while($n--)
{
fscanf(STDIN,"%s",$str);
  if($str[0]=='R'&& IsInt($str[1]) && IsType1($str))
  {
    $a=GetInt($str);
    $b=GetInt_D($str);
    echo conversion_int($b).$a."\n";
  }
  else {
    $a="";
    for($i=0;$i<strlen($str);$i++)
    {
      if(!IsInt($str[$i]))
      {
        $a.=$str[$i];
      }
      else {
        break;
      }
    }
    $b=GetInt_D($str);
      echo 'R'.$b.'C'.conversion_str($a)."\n";

  }
}
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
foreach ($input as $val) {
    if (preg_match('~^R([0-9]+)C([0-9]+)$~', $val, $matches)) {
        $r = $matches[1];
        $c = $matches[2];
        $cStr = '';
        $p = 0;
        while ($c > 0) {
            $s = $c % pow(26, $p + 1);
            $l = $s / pow(26, $p);
            if (! $l) {
                $l = 26;
            }
            $cStr = chr(64 + $l) . $cStr;
            $c -= $l * pow(26, $p);
            $p ++;
        }
        echo $cStr . $r . "\n";
    } elseif (preg_match('~^([A-Z]+)([0-9]+)$~', $val, $matches)) {
        $r = $matches[2];
        $cStr = $matches[1];
        $cStrLen = strlen($cStr);
        $c = 0;
        for ($i = 0; $i < $cStrLen; $i ++) {
            $l = substr($cStr, $i, 1);
            $l = ord($l) - 64;
            $c += $l * pow(26, $cStrLen - $i - 1);
        }
        echo 'R' . $r . 'C' . $c . "\n";
    }
}

<?php
function new2old($num) {
    $res="";
    while ($num>0)
    {
        $r=($num-1)%26;
        $res = chr($r+65).$res;
        $num = floor(($num-1)/26);
    }
    return $res;
}

function old2new($str) {
    $res=0;
    for ($i=0; $i<strlen($str); $i++){
        $res = $res*26;
        $res = $res + (ord($str[$i])-65);
        $res++;
    }
    return $res;
}

fscanf(STDIN,"%d\n",$n);
for ($i=0; $i<$n; $i++) {
    fscanf(STDIN,"%s\n",$line);
    if (ereg("R([0-9]+)C([0-9]+)", $line, $regs))
        print(new2old($regs[2]).$regs[1]."\n");
    elseif (ereg("([A-Z]+)([0-9]+)", $line, $regs))
        print("R".$regs[2]."C".old2new($regs[1])."\n");
}
?>

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets_trim($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = fgets_trim($stdin);

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param $stdin
 *
 * @return string
 */
function fgets_trim($stdin) {
    return trim(fgets($stdin));
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 0) {
        $n--;
        $rem = $n % 26;
        echo chr($rem + 65);
        $n = floor($n / 26);
    }

    return strrev(ob_get_clean());
}

<?php

$fr = fopen("php://stdin", "r");
$n = fgets($fr);

for($i=0;$i<$n;$i++)
{
    $input = fgets($fr);

    if( preg_match('/R([0-9]+)C([0-9]+)/i', $input, $matches) )
    {
        toStrY($matches);
    }
    elseif( preg_match('/([A-Z]+)([0-9]+)/i', $input, $matches) )
    {
        toRXCY($matches);
    }

}

function toStrY($target)
{
    $ch = $target[2];
    $str = '';

    while($ch)
    {
        $str = chr(65 + ($ch-1)%26) . $str;
        $ch = (integer)(($ch - ($ch-1)%26)/26);
    }
    printf("%s%s\n", $str, $target[1]);
}

function toRXCY($target)
{
    $str = $target[1];
    $len = strlen($str);
    $d = 1;
    $y = 0;
    for($j=$len-1;$j>=0;$j--)
    {
        $y += (ord($str[$j])-64)*$d;
        $d*=26;
    }
    printf("R%sC%s\n",$target[2],$y);
}

<?php

$fr = fopen("php://stdin", "r");
$n = fgets($fr);

for($i=0;$i<$n;$i++)
{
    $input = fgets($fr);

    if( preg_match('/R([0-9]+)C([0-9]+)/i', $input, $matches) )
    {
        toStrY($matches);
    }
    elseif( preg_match('/([A-Z]+)([0-9]+)/i', $input, $matches) )
    {
        toRXCY($matches);
    }
}

function toStrY($target)
{
    $col = $target[2];
    $str = '';

    while($col)
    {
        $str = chr(65 + ($col-1)%26) . $str;
        $col = (integer)(($col - ($col-1)%26)/26);
    }
    printf("%s%s\n", $str, $target[1]);
}

function toRXCY($target)
{
    $tar1 = $target[1];
    $len = strlen($tar1);
    $d = 1;
    $y = 0;

    for($j=$len-1;$j>=0;$j--)
    {
        $y += (ord($tar1[$j])-64)*$d;
        $d*=26;
    }
    printf("R%sC%s\n",$target[2],$y);
}

fclose($fr);

<?php
	$data = array();
    fscanf(STDIN, "%d\n", $n);
    for($i=0; $i<$n; $i++) {
    	fscanf(STDIN, "%s\n", $data[$i]);
    	if($data[$i][0] == 'R' && ord($data[$i][1]) >= 48 && ord($data[$i][1]) <= 57 && strpos($data[$i], 'C') !== false) {
    		$column = '';
    		$string = '';
    		$flag = false;
    		for($j = 1; $j < strlen($data[$i]); $j++) {
    			if($data[$i][$j] == 'C') {
    				$flag = true;
    			} else {
    				if(!$flag) {
    					$string .= $data[$i][$j];
    				} else {
    					$column .= $data[$i][$j];
    				}
    			}
    		}
    		$strColumn = '';
    		$column = (int)$column;

    		do {
    			if($column > 26) {
    				if($column % 26 != 0) {
		    			$strColumn .= chr($column % 26 + 64);
		    			$column = floor($column / 26);
		    		} else {
		    			$strColumn .= chr(26 + 64);
		    			$column = floor(($column-26) / 26);
		    		}
	    		} else {
	    			$strColumn .= chr($column + 64);
	    			break;
	    		}
    		} while(true);

    		$data[$i] = strrev($strColumn) . $string;

    	} else {
    		$column = '';
    		$string = '';
    		for($j = 0; $j<strlen($data[$i]); $j++) {
    			if(ord($data[$i][$j]) >= 65 &&  ord($data[$i][$j]) <= 90) {
    				$column .= $data[$i][$j];
    			} else {
    				$string .= $data[$i][$j];
    			}
    		}

    		$columnNum = 0;
    		for($j = strlen($column) - 1; $j >= 0; $j--) {
    			$columnNum += (ord($column[$j]) - 64) * pow(26, strlen($column)-$j-1);
    		}
    		$data[$i] = 'R' . $string . 'C' . $columnNum;
    	}
    }
    echo implode("\n", $data);
?>

<?php
# 1B
CONST LETTERS = 'ZABCDEFGHIJKLMNOPQRSTUVWXYZ';
function zz2rc($column, $row) {
    $columnNumber = 0;
    for ($i = strlen($column) - 1, $j = 0; $i >=0; $i--, $j++) {
        $pos = strpos(LETTERS, $column[$i], 1);
        $columnNumber += $pos * (26 ** $j);
    }
    return 'R' . $row . 'C' . $columnNumber;
}

function rc2zz($column, $row) {
    $columnNumber = '';
    while (($column / 26) > 1) {
        $floor = (int)floor($column / 26);
        $mod = $column % 26;
        $columnNumber .= LETTERS[$mod];
        $column = $floor;
        if ($mod === 0) {
            $column--;
        }
    }
    $ost = $column % 26;
    $columnNumber .= LETTERS[$ost];
    return strrev($columnNumber) . $row;
}

$n = fscanf(STDIN, '%u');
while ($row = trim(fgets(STDIN))) {
    if (preg_match('~R(\d+)C(\d+)~', $row, $match)) {
        echo rc2zz($match[2], $match[1]);
    } elseif(preg_match('~([A-Z]+)(\d+)~i', $row, $match)) {
        echo zz2rc($match[1], $match[2]);
    }
    echo PHP_EOL;
}

<?php
# 1B
CONST LETTERS = 'ZABCDEFGHIJKLMNOPQRSTUVWXYZ';
CONST LETTERS_MAP = [
    'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10
    , 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19
    , 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
];
function zz2rc(string $column, int $row): string {
    $columnNumber = 0;
    for ($i = strlen($column) - 1, $j = 0; $i >=0; $i--, $j++) {
        $pos = LETTERS_MAP[$column[$i]];
        $columnNumber += $pos * (26 ** $j);
    }
    return 'R' . $row . 'C' . $columnNumber;
}

function rc2zz(int $column, int $row): string {
    $columnNumber = '';
    while (($div = $column / 26) > 1) {
        $floor = (int)floor($div);
        $mod = $column % 26;
        $columnNumber .= LETTERS[$mod];
        $column = $floor;
        if ($mod === 0) {
            $column--;
        }
    }
    $mod = $column % 26;
    $columnNumber .= LETTERS[$mod];
    return strrev($columnNumber) . $row;
}

$n = fscanf(STDIN, '%u');
while ($row = trim(fgets(STDIN))) {
    if (preg_match('~R(\d+)C(\d+)~', $row, $match)) {
        echo rc2zz((int)$match[2], (int)$match[1]);
    } elseif(preg_match('~([A-Z]+)(\d+)~i', $row, $match)) {
        echo zz2rc($match[1], (int)$match[2]);
    }
    echo PHP_EOL;
}

<?php
# 1B
CONST LETTERS = 'ZABCDEFGHIJKLMNOPQRSTUVWXYZ';
CONST LETTERS_MAP = [
    'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10
    , 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19
    , 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
];
function zz2rc($column, $row) {
    $columnNumber = 0;
    for ($i = strlen($column) - 1, $j = 0; $i >=0; $i--, $j++) {
        $pos = LETTERS_MAP[$column[$i]];
        $columnNumber += $pos * (26 ** $j);
    }
    return 'R' . $row . 'C' . $columnNumber;
}

function rc2zz($column, $row) {
    $columnNumber = '';
    while (($div = $column / 26) > 1) {
        $floor = (int)floor($div);
        $mod = $column % 26;
        $columnNumber .= LETTERS[$mod];
        $column = $floor;
        if ($mod === 0) {
            $column--;
        }
    }
    $mod = $column % 26;
    $columnNumber .= LETTERS[$mod];
    return strrev($columnNumber) . $row;
}

$n = fscanf(STDIN, '%u');
while ($row = trim(fgets(STDIN))) {
    if (preg_match('~R(\d+)C(\d+)~', $row, $match)) {
        echo rc2zz($match[2], $match[1]);
    } elseif(preg_match('~([A-Z]+)(\d+)~i', $row, $match)) {
        echo zz2rc($match[1], $match[2]);
    }
    echo PHP_EOL;
}

<?php

$chars = "ZABCDEFGHIJKLMNOPQRSTUVWXY";

function transCol($col){
    global $chars;
    $step = 26;
    $return = '';
    while( $col ){
        $mod = $col % $step;
        $return = $chars[$mod] .$return;

        if($mod == 0){
            $col = $col-$step;
        }else{
            $col = $col-$mod;
        }

        $col = $col / $step;
    }

    return $return;
}

if( STDIN ) {
	$i = 0;
    $step = 26;
    while (!feof(STDIN)) {
            $line = trim(fgets(STDIN)); // stream_get_line(STDIN, 4096, "n");
            if( !empty($line) && $i++  ) {
				$hasR = 0;
				if($line[0] == 'R' && ((int)$line[1])) {
                    $c_pos = strpos($line,'C');
                    if( $c_pos !== false && is_numeric($line[$c_pos-1])){
                        $hasR = 1;
                    }
                }

				if($hasR){
                    $line = substr($line,1) ;
                    $item = explode("C",$line);
                    $row = $item[0];
                    $col = $item[1];

                    $colNew = transCol($col);
                    echo $colNew.$row."\n";
				}else{
                    $count = strlen($line);
                    $last_pos = 0;
                    for($pos=0;$pos<$count;$pos++){
                        $char = $line[$pos];
                        if(is_numeric($char)  && !$last_pos) {
                            $last_pos = $pos;
                        }
                    }

                    $col_word = substr($line,0,$last_pos);
                    $row = substr($line,$last_pos);

                    $level = 0;
                    $chars_arr = str_split($chars);
                    $amount = 0;
                    for(;$last_pos>0;$last_pos--){
                        $char = $col_word[$last_pos-1] ;
                        $index = array_search($char,$chars_arr);

                        if($index == 0){
                            $num = 26;
                        }else{
                            $num = $index;
                        }
                        $amount += pow($step,$level) * $num;

                        $level ++;
                    }

                    echo "R".$row."C".$amount."\n";

				}

            }
    }
}

<?php

$f = STDIN;
$n = fgets($f);

for($i = 0; $i < $n; $i++) {
    $input = fgets($f);

    if(preg_match('/R(\d+)C(\d+)/i', $input, $matches)) {
        $r = $matches[1];
        $c = $matches[2];

        toCR($r, $c);
    } else if(preg_match('/([A-Za-z]+)([0-9]+)/i', $input, $matches)) {

        $r = $matches[2];
        $c = $matches[1];
        toRxCy($r, $c);
    }
}

fclose($f);

function toRxCy($r, $c)
{
    $outR = $r;
    $outC = 0;

    $len = strlen($c);
    $d = 1;

    for($j=$len-1; $j>=0; $j--)
    {
        $outC += (ord($c[$j])-64)*$d;
        $d*=26;
    }

    printf("R%sC%s\n", $outR, $outC);
}

function toCR($r, $c)
{
    $outR = $r;
    $outC = '';

    while($c)
    {
        $outC = chr(65 + ($c-1)%26) . $outC;
        $c = (integer)(($c - ($c-1)%26)/26);
    }

    printf("%s%s\n", $outC, $outR);
}

<?php
/**
 * B. Spreadsheets
 * time limit per test10 seconds
 * memory limit per test64 megabytes
 * inputstandard input
 * outputstandard output
 * In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.
 *
 * The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.
 *
 * Input
 * The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .
 *
 * Output
 * Write n lines, each line should contain a cell coordinates in the other numeration system.
 *
 * Examples
 * input
 * 2
 * R23C55
 * BC23
 * output
 * BC23
 * R23C55
 */

$f = STDIN;
$n = fgets($f);

for($i = 0; $i < $n; $i++) {
    $input = fgets($f);

    if(preg_match('/R(\d+)C(\d+)/i', $input, $matches)) {
        $r = $matches[1];
        $c = $matches[2];

        toCR($r, $c);
    } else if(preg_match('/([A-Za-z]+)([0-9]+)/i', $input, $matches)) {

        $r = $matches[2];
        $c = $matches[1];
        toRxCy($r, $c);
    }
}

fclose($f);

function toRxCy($r, $c)
{
    $outR = $r;
    $outC = 0;

    $len = strlen($c);
    $d = 1;

    for($j=$len-1; $j>=0; $j--)
    {
        $outC += (ord($c[$j])-64)*$d;
        $d*=26;
    }

    printf("R%sC%s\n", $outR, $outC);
}

function toCR($r, $c)
{
    $outR = $r;
    $outC = '';

    while($c)
    {
        $outC = chr(65 + ($c-1)%26) . $outC;
        $c = (integer)(($c - ($c-1)%26)/26);
    }

    printf("%s%s\n", $outC, $outR);
}

<?php
class Parser {
	private $eq = array(
		'A'=>1,
		'B'=>2,
		'C'=>3,
		'D'=>4,
		'E'=>5,
		'F'=>6,
		'G'=>7,
		'H'=>8,
		'I'=>9,
		'J'=>10,
		'K'=>11,
		'L'=>12,
		'M'=>13,
		'N'=>14,
		'O'=>15,
		'P'=>16,
		'Q'=>17,
		'R'=>18,
		'S'=>19,
		'T'=>20,
		'U'=>21,
		'V'=>22,
		'W'=>23,
		'X'=>24,
		'Y'=>25,
		'Z'=>26,
	);

	public function ex2rc($ex){
		$rc = array();
		preg_match('/([A-Z]+)(\d+)/', $ex, $rc);
		$auxCol = array_reverse(str_split($rc[1]));
		$auxPot = 0;
		$col = 0;
		$row = $rc[2];
		foreach($auxCol as $l){
			$col = $col + $this->eq[$l] * pow(count($this->eq), $auxPot);
			$auxPot++;
		}
		return sprintf('R%sC%s', $row, $col);
	}
	public function rc2ex($rc){
		$n = count($this->eq);
		$ex = array();
		preg_match('/R(\d+)C(\d+)/', $rc, $ex);
		$auxCol = intval($ex[2]);
		$col = '';
		$row = $ex[1];
		$sub = false;
		while($auxCol / $n > 0){
			$r = $auxCol % $n;
			$auxCol = $auxCol - $r;
			$auxCol = $auxCol / $n;
			if($r == 0){
				$col = array_search($n, $this->eq) . $col;
				$auxCol--;
			} else {
				$col = array_search($r, $this->eq) . $col;
			}
		}
		return sprintf('%s%s', $col, $row);
	}

	public function transform($coordinate){
		if(preg_match('/R\d+C\d+/', $coordinate)){
			return $this->rc2ex($coordinate);
		}
		return $this->ex2rc($coordinate);
	}
}

$n = intval(rtrim( fgets( STDIN ) ));
$coordinates = array();
for($i = 0; $i < $n; $i++){
	$coordinates[] = rtrim( fgets( STDIN ) );
}

$p = new Parser();
for($i = 0; $i < $n; $i++){
	echo $p->transform($coordinates[$i]) . PHP_EOL;
}

<?php
	define("MOD", 26);
	$alph = array(
		"A" => 1,
		"B" => 2,
		"C" => 3,
		"D" => 4,
		"E" => 5,
		"F" => 6,
		"G" => 7,
		"H" => 8,
		"I" => 9,
		"J" => 10,
		"K" => 11,
		"L" => 12,
		"M" => 13,
		"N" => 14,
		"O" => 15,
		"P" => 16,
		"Q" => 17,
		"R" => 18,
		"S" => 19,
		"T" => 20,
		"U" => 21,
		"V" => 22,
		"W" => 23,
		"X" => 24,
		"Y" => 25,
		"Z" => 26
	);
	$alph_2 = array(
		"A",
		"B",
		"C",
		"D",
		"E",
		"F",
		"G",
		"H",
		"I",
		"J",
		"K",
		"L",
		"M",
		"N",
		"O",
		"P",
		"Q",
		"R",
		"S",
		"T",
		"U",
		"V",
		"W",
		"X",
		"Y",
		"Z"
	);

	$count = (int)fgets(STDIN);
	$input_array = array();
	for ($i = 0; $i < $count; $i++){
		array_push($input_array, trim(fgets(STDIN)));
	}
	for ($j = 0; $j < $count; $j++){
		$input_number = $input_array[$j];
		$number_array = array();
		$letter_array = array();
		$letter = "";
		$number = "";
		for ($i =0; $i < strlen($input_number); $i++){
			if(!is_numeric($input_number[$i])){
				if($number !== ""){
					array_push($number_array, (int)$number);
					$number = "";
				}
				$letter .= $input_number[$i];
			}
			else{
				if($letter !== ""){
					array_push($letter_array, (string)$letter);
					$letter = "";
				}
				$number .= $input_number[$i];
			}
		}
		if($number !== ""){
			array_push($number_array, (int)$number);
			$number = "";
		}
		if($letter !== ""){
			array_push($letter_array, (string)$letter);
			$letter = "";
		}

		if(count($number_array) === 2){
			$res = array();
			$p = $number_array[1];
			$q = 0;
			while ($p > MOD){
				$tmp_q = $p % MOD;
				if ($tmp_q === 0){
					$q = MOD;
					$p = intval($p / MOD) - 1;
				}
				else{
					$p = intval($p / MOD);
					$q = $tmp_q;
				}
				array_push($res, $q);
			}
			array_push($res, $p);
			$count_res = count($res) - 1;
			for ($i = $count_res; $i >= 0; $i--){
				echo $alph_2[$res[$i] - 1];
			}
			echo $number_array[0]."\n";
		}
		else{
			$letters = $letter_array[0];
			$res_number = 0;
			for ($i = 0; $i < strlen($letters); $i++){
				$res_number += pow(MOD, (strlen($letters) - 1) - $i ) * $alph[$letters[$i]];
			}
			echo "R" . $number_array[0] . "C" . $res_number . "\n";
		}
	}
?>

<?php
function number_to_alpha($num) {
  $str = '';
  $num = (int)$num;
  $continue = false;
  do {
    $continue = $num > 26;
    if ($continue) {
      $curr_num = $num % 26;
      if ($curr_num === 0) {
        $str = 'Z'.$str;
        $num = floor($num / 26) - 1;
      } else {
        $str = chr($curr_num + 64).$str;
        $num = floor($num / 26);
      }
    } else {
      $str = chr($num + 64).$str;
    }
  } while ($continue);
  return $str;
}

function alpha_to_number($str) {
  $parts = str_split($str);
  $num = 0;
  for ($i = 0; $i < count($parts); $i++) {
    $num = $num * 26;
    $num += ord($parts[$i]) - 64;
  }
  return $num;
}

function convert_one($str) {
  $parts = preg_split("/\d+/", $str);
  if ($parts[0] === 'R' && $parts[1] === 'C') {
    // from RXCY
    $numbers = preg_split("/R|C/", $str);
    $row = $numbers[1];
    $col = $numbers[2];
    printf("%s%d\n", number_to_alpha($col), $row);
  } else {
    // to RXCY
    $col_str = $parts[0];
    $col = alpha_to_number($col_str);
    $row_parts = preg_split("/[A-Z]+/", $str);
    $row = (int)$row_parts[1];
    printf("R%dC%d\n", $row, $col);
  }
}

fscanf(STDIN, "%d", $n);
for ($i = 1; $i <= $n; $i++) {
  fscanf(STDIN, "%s", $str);
  convert_one($str);
}
?>

<?php

	$first_marker = 0;
	$second_marker = 0;
	function conv2 ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = numToLet($second);
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i);
				$second = substr($string, $i);
				break;
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

	function numToLet ($num){
		$raz = 1;
		$newnum = $num;
		while (($newnum/26)>1.03845) {
			if ((int)$newnum/26 != 27 AND $newnum!=18278 AND ($newnum<474547 OR $newnum>474551) AND ($newnum<475229 OR $newnum>475254)) {
			$raz++;
			}
			$newnum /= 26;
		}
		$newnum = $num;
		$res = '';
		for ($i=0;$i<$raz;$i++) {
			$cur = $newnum%26;
			switch ($cur) {
				case 1: $res = 'A'.$res; break;
				case 2: $res = 'B'.$res; break;
				case 3: $res = 'C'.$res; break;
				case 4: $res = 'D'.$res; break;
				case 5: $res = 'E'.$res; break;
				case 6: $res = 'F'.$res; break;
				case 7: $res = 'G'.$res; break;
				case 8: $res = 'H'.$res; break;
				case 9: $res = 'I'.$res; break;
				case 10: $res = 'J'.$res; break;
				case 11: $res = 'K'.$res; break;
				case 12: $res = 'L'.$res; break;
				case 13: $res = 'M'.$res; break;
				case 14: $res = 'N'.$res; break;
				case 15: $res = 'O'.$res; break;
				case 16: $res = 'P'.$res; break;
				case 17: $res = 'Q'.$res; break;
				case 18: $res = 'R'.$res; break;
				case 19: $res = 'S'.$res; break;
				case 20: $res = 'T'.$res; break;
				case 21: $res = 'U'.$res; break;
				case 22: $res = 'V'.$res; break;
				case 23: $res = 'W'.$res; break;
				case 24: $res = 'X'.$res; break;
				case 25: $res = 'Y'.$res; break;
				case 0: $res = 'Z'.$res; break;
			}
			if ($cur==0){
			$newnum = floor($newnum/26)-1;
			}
			else {
			$newnum/=26;
			}
		}
		return $res;
	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
		    $cur = (ord($let[$i])-64);
			if ($i<(strlen($let)-1)) {
			$sum = $sum + $cur*pow(26,(strlen($let)-$i-1));
			}
			else {
			$sum += $cur;
			}
		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php

	function conv2 ($string) {
	$first_marker = 0;
	$second_marker = 0;
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = numToLet($second);
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i);
				$second = substr($string, $i);
				break;
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {
	$first_marker = 0;
	$second_marker = 0;

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

function numToLet ($num){
		$res="";
		while ($num>0)
		{
			$res = chr((($num-1)%26)+65).$res;
			$num = floor(($num-1)/26);
		}
    return $res;

	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
			$sum += ($i<(strlen($let)-1)) ? (ord($let[$i])-64)*pow(26,(strlen($let)-$i-1)) : (ord($let[$i])-64);

		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));

function convertS1($input){
	$nums = ["1","2","3","4","5","6","7","8","9","0"];
	$col ="";
	$col_num =0;
	$row =0;
	$inputs = str_split($input);
	for ($i=0; $i < count($inputs); $i++) {
		if(in_array($inputs[$i], $nums)){
			// echo "AA-".$inputs[$i]."\n";
			$col = substr($input, 0, $i);
			$row = intval(substr($input, $i));
			break;
		}
	}
	$cols = str_split($col);
	for ($i=0; $i < count($cols); $i++) {

		$col_num += ( pow(26,(count($cols)-$i-1))*( ord($cols[$i]) - ord("A") +1 ) );
		// if($i==count($cols)-1){
		// 	$col_num += ( ord($cols[$i]) - ord("A") +1 ) ;
		// }else{

		// }
	}
	return "R{$row}C{$col_num}";

}

function convertS2($input){
	$inputs = explode("C",$input);
	$col =0;
	$col_char ="";
	$row =0;
	$row = intval(str_replace("R", "", $inputs[0]));
	$col = intval($inputs[1]);
	$flag=true;
	while(true){
		if($col%26>0){
			$col_char = chr(($col%26)+64) . $col_char;
		}else{
			$col_char = chr(26+64) . $col_char;
			$col -= 26;
		}
		$col = intval($col/26);
		if($col<=0){
			break;
		}
	}
	return "{$col_char}{$row}";
}
$inputs=[];
for ($i=0; $i < $n; $i++) {
	$inputs[] = strval(trim(fgets(STDIN)));

}
for ($i=0; $i < $n; $i++) {
	if($i>0)echo "\n";
	$input = $inputs[$i];
	if (!preg_match('/R(\d+)C(\d+)/',
                $input))
	{
	 	echo convertS1($input);
	}
	else
	{
		echo convertS2($input);
	}

}

<?php
function convertRCtoCR($cell){
    $st = preg_match('/^R([0-9]+)C([0-9]+)$/', trim($cell), $matches);
    #var_dump($st, $matches);
    $row = $matches[1]; // not modified
    $column = $matches[2];
    $str = ""; //character representation of column

    while( $column > 0){
        $char = ($column%26>0)?$column%26:26;
        $column = intval($column/26);
        $column = ($char==26)?$column-1:$column;
        $str = chr($char+64) . $str;
        #var_dump($char, $column, $str);
    }
    return $str.''.$row;
}

function convertCRtoRC($cell){
    $st = preg_match('/^([A-Z]+)([0-9]+)$/', trim($cell), $matches);
    #var_dump($st, $matches);
    $column = $matches[1];
    $row = $matches[2]; //not modified
    $chs = str_split($column);
    $count = strlen($column);
    $column = 0;
    foreach($chs as $ch){
        $column += (ord($ch) - 64) * 26**($count -1);
        $count--;
    }
    return 'R' . $row . 'C' . $column;
}

function convert($cell){
    $type = preg_match('/^R[0-9]+C[0-9]+$/', trim($cell), $matches);
    #var_dump($type, $matches);
    if($type === 1){
        return convertRCtoCR($cell);
    }

    return convertCRtoRC($cell);
}

$dir = fopen("php://stdin", 'r');
$cells = stream_get_contents($dir);

$cells = explode("\n", $cells);
for($i=1;$i<=$cells[0];$i++){
    echo convert($cells[$i])."\n";
}
?>

<?php

$file = fopen("php://stdin", "r");
// $file = fopen("text.txt", "r");
$n = fgets($file);
for($i=0;$i<$n;$i++)
{
    $input = fgets($file);
    if( preg_match('[R([0-9]+)C([0-9]+)]', $input, $matches) )
    {
        RXCY($matches);
    }
    elseif( preg_match('[([A-Z]+)([0-9]+)]', $input, $matches) )
    {
        excel($matches);
    }
}

function RXCY($target){
    $row = $target[1];
    $column = $target[2];
    while($column){
        $newColumn = chr(65 + ($column-1)%26) . $newColumn;
        $column = (integer)(($column-($column-1)%26)/26);
    }
    echo $newColumn.$row."\n";

}
function excel($target){
    $str = $target[1];
    $column = 0;
    $len = strlen($str);
    $d = 1;
    for($i=$len-1;$i>=0;$i--){
        $column += (ord($str[$i])-64)*$d;
        $d *=26;
    }
    echo "R".$target[2]."C".$column."\n";
}

fclose($file);

?>

<?php
    fscanf(STDIN, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf(STDIN, "%s\n", $coords);
        $coords = str_split($coords);
        $letters = array();
        $digits = array();
        $RXCY = 0;
        while ($char = array_shift($coords)) {
            if (is_numeric($char)) {
                $digits[$RXCY] .= $char;
            } elseif(isset($digits[$RXCY]) && !$RXCY) {
                $RXCY = 1;
                $letters[$RXCY] .= $char;
            } else {
                $letters[$RXCY] .= $char;
            }
        }
        if ($RXCY) {
            $col = $digits[1];
            $colCode = '';
            while ($col > 26) {
                $letNum = floor($col / 26);
                $colCode .= chr(64 + $letNum);
                $col = $col % 26;
            }
            if ($col > 0) {
                $colCode .= chr(64 + $col);
            }
            $resultCode = $colCode . $digits[0];
        } else {
            $colArray = str_split($letters[0]);
            $colNum = 0;
            $power = 0;
            while ($let = array_pop($colArray)) {
                $colNum += (ord($let) - 64) * pow(26, $power++);
            }
            $resultCode = 'R' . $digits[0] . 'C' . $colNum;
        }
        echo "$resultCode\n";
    }
?>

<?php

$file = fopen("php://stdin", "r");
// $file = fopen("text.txt", "r");
$n = fgets($file);
fclose($file);
for($i=0;$i<$n;$i++)
{
    $input = fgets($file);
    if( preg_match('[R([0-9]+)C([0-9]+)]', $input, $matches) )
    {
        RXCY($matches);
    }
    elseif( preg_match('[([A-Z]+)([0-9]+)]', $input, $matches) )
    {
        excel($matches);
    }
}

function RXCY($target){
    $row = $target[1];
    $column = $target[2];
    $newColumn = "";
    while($column){
        $newColumn = chr($column%26+64).$newColumn;
        $column = (integer)($column-$column%26)/26;
    }
    echo $newColumn.$row."\n";

}
function excel($target){
    $str = $target[1];
    $column = 0;
    $len = strlen($str);
    $d = 1;
    for($i=$len-1;$i>=0;$i--){
        $column += (ord($str[$i])-64)*$d;
        $d *=26;
    }
    echo "R".$target[2]."C".$column."\n";
}

?>

<?php

$file = fopen("php://stdin", "r");
// $file = fopen("text.txt", "r");
$n = fgets($file);
for($i=0;$i<$n;$i++)
{
    $input = fgets($file);
    if( preg_match('[R([0-9]+)C([0-9]+)]', $input, $matches) )
    {
        RXCY($matches);
    }
    elseif( preg_match('[([A-Z]+)([0-9]+)]', $input, $matches) )
    {
        excel($matches);
    }
}

function RXCY($target){
    $row = $target[1];
    $column = $target[2];
    $newColumn = "";
    while($column){
        $newColumn = chr($column%26+64).$newColumn;
        $column = (integer)($column-$column%26)/26;
    }
    echo $newColumn.$row."\n";

}
function excel($target){
    $str = $target[1];
    $column = 0;
    $len = strlen($str);
    $d = 1;
    for($i=$len-1;$i>=0;$i--){
        $column += (ord($str[$i])-64)*$d;
        $d *=26;
    }
    echo "R".$target[2]."C".$column."\n";
}

fclose($file);

?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		echo numToChar($matches[2]).$matches[1].PHP_EOL;
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		echo 'R'.$matches[2].'C'.charToNum($matches[1]).PHP_EOL;
	}
}

<?php
	$data = array();
    fscanf(STDIN, "%d\n", $n);
    for($i=0; $i<$n; $i++) {
    	fscanf(STDIN, "%s\n", $data[$i]);
    	if($data[$i][0] == 'R' && ord($data[$i][1]) >= 48 && ord($data[$i][1]) <= 57) {
    		$column = '';
    		$string = '';
    		$flag = false;
    		for($j = 1; $j < strlen($data[$i]); $j++) {
    			if($data[$i][$j] == 'C') {
    				$flag = true;
    			} else {
    				if(!$flag) {
    					$string .= $data[$i][$j];
    				} else {
    					$column .= $data[$i][$j];
    				}
    			}
    		}
    		$strColumn = '';
    		$column = (int)$column;

    		do {
    			if($column > 26) {
    				if($column % 26 != 0) {
		    			$strColumn .= chr($column % 26 + 64);
		    			$column = floor($column / 26);
		    		} else {
		    			$strColumn .= chr(26 + 64);
		    			$column = floor(($column-26) / 26);
		    		}
	    		} else {
	    			$strColumn .= chr($column + 64);
	    			break;
	    		}
    		} while(true);

    		$data[$i] = strrev($strColumn) . $string;

    	} else {
    		$column = '';
    		$string = '';
    		for($j = 0; $j<strlen($data[$i]); $j++) {
    			if(ord($data[$i][$j]) >= 65 &&  ord($data[$i][$j]) <= 90) {
    				$column .= $data[$i][$j];
    			} else {
    				$string .= $data[$i][$j];
    			}
    		}

    		$columnNum = 0;
    		for($j = strlen($column) - 1; $j >= 0; $j--) {
    			$columnNum += (ord($column[$j]) - 64) * pow(26, strlen($column)-$j-1);
    		}
    		$data[$i] = 'R' . $string . 'C' . $columnNum;
    	}
    }
    echo "\n\n";
    echo implode("\n", $data);
?>

<?php

    function get_stdin_vars($str, $count) {
        $str =(string) $str;
        $count =(int) $count;
        $vars = array(); // for result
        $var_index = 0; // index of array vars
        $str_index = 0; // index of symbol in $str
        while($var_index <= $count) {
            while ($str_index<strlen($str)) {
                if($str[$str_index] != ' ' and $str[$str_index] != "\r") {
                    $vars[$var_index] .= $str[$str_index];
                }
                else {
                    if ($vars[$var_index] != '') {
                       $str_index++;
                       break;
                    }
                }
                $str_index++;
            }
            $var_index++;
        }
        return $vars;
    }

    function get_assocc_char($num) {
        global $alphabet;
        $num = (int) $num;
        $tmp = round($num/26);
        if($tmp != 0) { return get_assocc_char($tmp).$alphabet[$num%26]; }
        else { return $alphabet[$num%26];}
    }

    function convert($str) {
        global $alphabet;
        $matches = array();
        if (preg_match('#^R([0-9]*)C([0-9]*)$#',$str,$matches)==1) {
            $row = $matches[1];
            $col = get_assocc_char($matches[2]);
            return $col.$row;
        }
        elseif(preg_match('#^([A-Z]*)([0-9]*)$#',$str,$matches)==1) {
            $row = $matches[2];
            $col = $matches[1];
            $colnum = 0;
            $col_length = strlen($col);
            $base = 1;
            for($i=$col_length-1;$i>=0;$i--) {
                if($i != $col_length-1) { $base = $base * 26; };
                $colnum = $colnum + $base * $alphabet[$col[$i]];
            }
            return 'R'.$row.'C'.$colnum;
        }
        else { die("Error: ".$str." - unknown pattern\n"); }
    }

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

    $alphabet = array (1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M',
            14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z',
            'A'=>1,'B'=>2,'C'=>3,'D'=>4,'E'=>5,'F'=>6,'G'=>7,'H'=>8,'I'=>9,'J'=>10,'K'=>11,'L'=>12,'M'=>13,
            'N'=>14,'O'=>15,'P'=>16,'Q'=>17,'R'=>18,'S'=>19,'T'=>20,'U'=>21,'V'=>22,'W'=>23,'X'=>24,'Y'=>25,'Z'=>26);
    $count = get_stdin_vars(fgets(STDIN),1);
    $count = (int)$count[0];

    if($count<1 or $count>100000) {
        die('Error: number of elements must be in range 1-100000');
    }

    for ($i=0;$i<$count;$i++) {
        $indication = get_stdin_vars(fgets(STDIN),1);
        $indication = $indication[0];
        echo convert($indication)."\n";
    }
?>

<?php
/*
In the popular spreadsheets systems (for example, in Excel) the following numeration of
columns is used. The first column has number A, the second — number B, etc. till column
26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB,
column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation
of the column and the row numbers. For example, BC23 is the name for the cell that is in
column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
showing the column and the row numbers respectfully. For instance, R23C55 is the cell
from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and
produce each item written according to the rules of another numeration system.

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

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

Sample test(s)
Input
2
R23C55
BC23

Output
BC23
R23C55
*/
/*
$n = fgets(STDIN);
for ($i = 0; $i < $n; $i++)
    $r[$i] = fgets(STDIN);
*/

$n = 1;
$r[0] = 'R65114C109610';

for ($i = 0; $i < $n; $i++) {
    if (preg_match('"[R][0-9]{1,6}[C][0-9]{1,6}"',$r[$i]) == 1) {
        $s = preg_split('"[RC]"',$r[$i]);

        $s2 = $s[2];
        $d1 = '';
        while ($s2 > 0) {
            $d1 = chr(($s2 - 1) % 26 + 65) . $d1;
            $s2 = floor($s2 / 26);
            //echo "--$s2 $d1\n";
        }
        echo "$d1$s[1]\n";
        //print_r ($s);
    }
    else {
        $l = preg_split('"[0-9]"',$r[$i]);
        $d = preg_split('"[A-Z]"',$r[$i]);

        $l1 = str_split($l[0]);
        $re = 0;
        for ($j = 0; $j < count($l1); $j++) {
            $re = 26 * $re + ord($l1[$j]) - 64;
            //echo "$j $re\n";
        }
        $d1 = intval($d[count($d) - 1]);
        //print_r($l1);
        //print_r($d);
        echo "R$d1" . "C$re\n";
    }
}
?>

<?php

// $file = fopen("php://stdin", "r");
$file = fopen("text.txt", "r");
$n = fgets($file);
for($i=0;$i<$n;$i++)
{
    $input = fgets($file);
    if( preg_match('[R([0-9]+)C([0-9]+)]', $input, $matches) )
    {
        RXCY($matches);
    }
    elseif( preg_match('[([A-Z]+)([0-9]+)]', $input, $matches) )
    {
        excel($matches);
    }
}

function RXCY($target){
    $row = $target[1];
    $column = $target[2];
    $newColumn = "";
    while($column){
        $newColumn = chr($column%26+64).$newColumn;
        $column = (integer)($column-$column%26)/26;
    }
    echo $newColumn.$row."\n";

}
function excel($target){
    $str = $target[1];
    $column = 0;
    $len = strlen($str);
    $d = 1;
    for($i=$len-1;$i>=0;$i--){
        $column += (ord($str[$i])-64)*$d;
        $d *=26;
    }
    echo "R".$target[2]."C".$column."\n";
}

fclose($file);

?>

<?php
function convertRCtoCR($cell){
    $st = preg_match('/^R([0-9]+)C([0-9]+)$/', trim($cell), $matches);

    $row = $matches[1]; // not modified
    $column = $matches[2];
    $str = ""; //character representation of column

    while( $column%26 > 0){
        $char = $column%26;
        $column = intval($column/26);
        $str = chr($char+64) . $str;
    }
    return $str.$row;
}

function convertCRtoRC($cell){
    $st = preg_match('/^([A-Z]+)([0-9]+)$/', trim($cell), $matches);

    $column = $matches[1];
    $row = $matches[2]; //not modified
    $chs = str_split($column);
    $count = strlen($column);
    $column = 0;
    foreach($chs as $ch){
        $column += (ord($ch) - 64) * 26**($count -1);
        $count--;
    }
    return 'R' . $row . 'C' . $column;
}

function convert($cell){
    $type = preg_match('/^R[0-9]+C[0-9]+$/', trim($cell), $matches);

    if($type === 1){
        return convertRCtoCR($cell);
    }

    return convertCRtoRC($cell);
}

$dir = fopen("php://stdin", 'r');
$cells = stream_get_contents($dir);

$cells = explode("\n", $cells);
for($i=1;$i<=$cells[0];$i++){
    echo convert($cells[$i])."\n";
}
?>

<?php

$f = STDIN;
$n = fgets($f);

for($i = 0; $i < $n; $i++) {
    $input = fgets($f);

    if(preg_match('/R(\d+)C(\d+)/i', $input, $matches)) {
        $r = $matches[1];
        $c = $matches[2];

        toCR($r, $c);
    } else if(preg_match('/([A-Za-z]+)([0-9]+)/i', $input, $matches)) {

        $r = $matches[2];
        $c = $matches[1];
        toRxCy($r, $c);
    }
}

fclose($f);

function toRxCy($r, $c)
{
    $outR = $r;
    $outC = 0;

    $len = strlen($c);
    $d = 1;

    for($j=$len-1; $j>=0; $j--)
    {
        $outC += (ord($c[$j])-64)*$d;
        $d*=26;
    }

    printf('R%sC%s\n', $outR, $outC);
}

function toCR($r, $c)
{
    $outR = $r;
    $outC = '';

    while($c)
    {
        $outC = chr(65 + ($c-1)%26) . $outC;
        $c = (integer)(($c - ($c-1)%26)/26);
    }

    printf('%s%s\n', $outC, $outR);
}

<?php

function toAlpha($num){
        $res="";
        while ($num>0)
        {
                $r=($num-1)%26;
                $res = chr($r+65).$res;
                $num = floor(($num-1)/26);
        }
        return $res;
}

function toNum($string){
        $int = 0;
        $len = strlen($string);
        for($i = 0; $i< $len; $i++){
                $int*=26;
                $int += ord($string[$i]) - 64;
        }
        return $int;
}

$file = fscanf(STDIN, "%d\n", $cells);
for($i=0; $i<$cells; $i++){
        fscanf(STDIN, "%s\n", $line);
        if($line[0] == 'R' && ord($line[1])>=48&&ord($line[1])<=57){
                $cPos = strpos($line, 'C', 2);
                if($cPos !== -1){
                        print(toAlpha(substr($line, $cPos+1)).substr($line, 1, $cPos-1)."\n");
                }else{
                        print('R'.substr($line, 1)."C18\n");
                }
        }else{
                preg_match('/[0-9]/', $line, $matches, PREG_OFFSET_CAPTURE);
                print('R'.substr($line, $matches[0][1]).'C'.toNum(substr($line, 0, $matches[0][1]))."\n");
        }
}

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = fgets($stdin);

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    } else {
        preg_match("/^R([0-9]+)C([0-9]+)$/", $coords, $matches);
        var_dump($matches);
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 26) {
        echo to_letter($n);
        $n /= 26;
    }

    echo to_letter($n);

    return strrev(ob_get_clean());
}

/**
 * @param int $n
 *
 * @return string
 */
function to_letter($n) {
    return chr($n % 26 + 64);
}

<?php
$inp = fopen("php://stdin", 'r');
$str = stream_get_contents($inp);
$params = explode("\r\n", $str);

$n = $params[0];
$cells = array_slice($params, 1);
$letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$patternRC = '/R([\d]*)C([\d]*)/';
$patternA1 = '/([A-Z]+)([0-9]+)/';

foreach($cells as $cell){
    if(preg_match($patternRC, $cell, $matches)){
        $r = $matches[1];
        $c = $matches[2];
        echo num2alpha($c, $letters).$r.PHP_EOL;
    } else if  (preg_match($patternA1, $cell, $matches)){
        $r = $matches[2];
        $c = $matches[1];
        echo "R".$r."C".alpha2num($c, $letters).PHP_EOL;
    }
}

function num2alpha($n, $letters){
    $c = '';

    for($i = $n; $i > 0; $i = floor($i / 26)){
        $k = ($i % 26);
        if($k == 0){
            $k = 26;
            $i--;
        }
        $c = $letters[$k-1].$c;
    }

    return $c;
}

function alpha2num($n, $letters){
    $c = 0;

    for($i = strlen($n), $j = 0; $i > 0;$i--,$j++){
        $k = array_search($n[$i-1], $letters) + 1;
        if($j > 0){
            $k = $k * pow(26, $j);
        }
        $c = $k + $c;
    }

    return $c;
}

?>

<?php

$n = 0;

fscanf(STDIN, "%d", $n);

for ($iv = 0; $iv < $n; $iv++) {
    fscanf(STDIN, "%s", $var);

    if(preg_match("/R([0-9]+)C([0-9]+)/", $var, $matches)){
        $new = "";
        mytostr((int)$matches[2], $new);
        print $new.$matches[1]."\n";
    }
    elseif ( preg_match("/([A-Z]+)([0-9]+)/", $var, $matches) ) {
        $new = 0;
        mytoint($matches[1], $new);
        print "R".$matches[2]."C".$new."\n";
    }
}

function mytostr($param, &$result) {
    $result = "";

    while($param >= 1)
    {
        $t = $param % 26;
        if($t == 0 && $param == 26) {
            $t = 26;
            $param = 0;
        }
        $result = chr($t + ord("A") - 1) . $result;
        $param = floor($param / 26) ;
    }

    //R98C688
    //R90C35
}

function mytoint($param, &$result) {
    $result = 0;
    for ($index = 0; $index < strlen($param); $index++) {
        $result += (ord($param[$index]) - ord("A") + 1) * pow(26, (strlen($param) - $index - 1));
    }
}

?>

<?php

$stdin = fopen('php://stdin', 'r');

fscanf($stdin, "%d", $n);

$results = array();
for($i = 0; $i < $n; $i++)
{
	 fscanf($stdin, "%s", $str);
	 $results[] = $str;
}

$baseNum = 26;
$baseChar = ord('A') - 1;

for($i = 0; $i < $n; $i++)
{
	$str = $results[$i];

	$matches = array();

	$res = '';

	if(preg_match('/R(\d+)C(\d+)/', $str, $matches))
	{
		$num = $matches[2];

		while($num > $baseNum)
		{
			$left = $num % $baseNum;
			if(!$left)
			{
				$left = 26;
			}

			$res = chr($left + $baseChar) . $res;
			$num  = intval($num  / $baseNum);

		}

		if($num)
		{
			$res = chr($num + $baseChar) . $res;
		}

		$res .= $matches[1];

		echo $res . PHP_EOL;
	}
	else
	{
		preg_match('/([A-Z]+)(\d+)/', $str, $matches);

		$res = 'R' . $matches[2] . 'C';

		$str = str_split($matches[1]);
		$pos = count($str) - 1;
		$sum = 0;
		foreach($str as $chr)
		{
			$sum += (ord($chr) - $baseChar) * pow($baseNum, $pos);
			$pos--;
		}

		echo $res . $sum . PHP_EOL;

	}
}

<?php
$n = readline();
$spreadSheetArray = [];
for ($i = 0; $i < $n; $i++){
    $temp = readline();
    array_push($spreadSheetArray, $temp);
}

for ($i = 0; $i < count($spreadSheetArray); $i++){
    if (isRCNotation($spreadSheetArray[$i])){
        convertToNormal($spreadSheetArray[$i]);
    }
    else{
        convertToRC($spreadSheetArray[$i]);
    }
}

function isRCNotation($value){
    $numberReached = false;
    $RCNotation = false;
    $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

    for ($i = 0; $i < strlen($value); $i++){
        if (in_array($value[$i], $digits)){
            $numberReached = true;
        }
        if ($numberReached){
            if (!in_array($value[$i], $digits)){
                $RCNotation = true;
                break;
            }
        }
    }

    return $RCNotation;
}

function convertToNormal($word){
    $normal = "";
    $indexes = array();
    $alphabet = ['Z', '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'];

    $posR = strpos($word, 'R');
    $posC = strpos($word, 'C');

    $row = substr($word, $posR + 1, $posC-1);
    $col = substr($word, $posC + 1);

    if($col <= 25){
        $remainder = $col % 26;
        array_push($indexes, $remainder);
    }
    else{
        while($col > 25){
            $remainder = $col % 26;
            array_push($indexes, $remainder);
            if($remainder == 0){
                $col = ($col / 26) -1;
                if($col == 0){
                    break;
                }
            }
            else{
                $col = $col / 26;
            }
            print ("REM: ".$col."\n");
            if ($col / 26 < 25){
                $col = floor($col);
                array_push($indexes, $col);
            }
        }
    }

    $rereversedIndexes = array_reverse($indexes);
    for ($i = 0; $i < sizeof($indexes); $i++){
        $normal = $normal.$alphabet[$rereversedIndexes[$i]];
    }

    print($normal.$row."\n");
}

function convertToRC($word){
    $rowNum = 0;

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

    for ($i = 0; $i < strlen($word); $i++){
        if(in_array($word[$i], $digits)){
            $index = $i;
            break;
        }
    }

    $rowRev = substr($word, 0, $index);
    $col = substr($word, $index);

    $row = strrev($rowRev);

    for($i = strlen($row)-1; $i >= 0; $i--){
        $rowNum += $alphabet[$row[$i]] * pow(26, $i);
    }

    print("R".$col."C".$rowNum."\n");
}

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, numToChar($matches[2]).$matches[1]);
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, 'R'.$matches[2].'C'.charToNum($matches[1]));
	}
}
?>

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%s", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$result .= chr(64 + $a % 26);
		$a = floor($a / 26);
	}
	return strrev($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

echo $n;
var_dump($a);

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "\n";
}
echo change($a[$n - 1]);

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$result .= chr(64 + $a % 26);
		$a = floor($a / 26);
	}
	return strrev($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "<br>";
}
echo change($a[$n - 1]);

<?php
$n = readline();
$spreadSheetArray = [];
for ($i = 0; $i < $n; $i++){
    $temp = readline();
    array_push($spreadSheetArray, $temp);
}

for ($i = 0; $i < count($spreadSheetArray); $i++){
    if (isRCNotation($spreadSheetArray[$i])){
        convertToNormal($spreadSheetArray[$i]);
    }
    else{
        convertToRC($spreadSheetArray[$i]);
    }
}

function isRCNotation($value){
    $numberReached = false;
    $RCNotation = false;
    $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

    for ($i = 0; $i < strlen($value); $i++){
        if (in_array($value[$i], $digits)){
            $numberReached = true;
        }
        if ($numberReached){
            if (!in_array($value[$i], $digits)){
                $RCNotation = true;
                break;
            }
        }
    }

    return $RCNotation;
}

function convertToNormal($word){
    $normal = "";
    $indexes = array();
    $alphabet = ['Z', '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'];

    $posR = strpos($word, 'R');
    $posC = strpos($word, 'C');

    $row = substr($word, $posR + 1, $posC-1);
    $col = substr($word, $posC + 1);
    print ("LENG: ".strlen($word)-$posC-1);
    print ("\nROW: ".$row."\n");
    print ("COL: ".$col."\n");

    if($col <= 25){
        $remainder = $col % 26;
        array_push($indexes, $remainder);
    }
    else{
        while($col > 25){
            $remainder = $col % 26;
            $col = $col / 26;
            array_push($indexes, $remainder);
            if ($col / 26 < 25){
                $col = floor($col);
                array_push($indexes, $col);
            }
        }
    }

    $rereversedIndexes = array_reverse($indexes);
    for ($i = 0; $i < sizeof($indexes); $i++){
        $normal = $normal.$alphabet[$rereversedIndexes[$i]];
    }

    print($normal.$row."\n");
}

function convertToRC($word){
    $rowNum = 0;

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

    for ($i = 0; $i < strlen($word); $i++){
        if(in_array($word[$i], $digits)){
            $index = $i;
        }
    }

    if($index == 1){
        $index = 2;
    }

    $rowRev = substr($word, 0, $index-1);
    $col = substr($word, $index-1);

    $row = strrev($rowRev);

    for($i = strlen($row)-1; $i >= 0; $i--){
        $rowNum += $alphabet[$row[$i]] * pow(26, $i);
    }

    print("R".$col."C".$rowNum."\n");
}

<?php
$n = readline();
$spreadSheetArray = [];
for ($i = 0; $i < $n; $i++){
    $temp = readline();
    array_push($spreadSheetArray, $temp);
}

for ($i = 0; $i < count($spreadSheetArray); $i++){
    if (isRCNotation($spreadSheetArray[$i])){
        convertToNormal($spreadSheetArray[$i]);
    }
    else{
        convertToRC($spreadSheetArray[$i]);
    }
}

function isRCNotation($value){
    $numberReached = false;
    $RCNotation = false;
    $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

    for ($i = 0; $i < strlen($value); $i++){
        if (in_array($value[$i], $digits)){
            $numberReached = true;
        }
        if ($numberReached){
            if (!in_array($value[$i], $digits)){
                $RCNotation = true;
                break;
            }
        }
    }

    return $RCNotation;
}

function convertToNormal($word){
    $normal = "";
    $indexes = array();
    $alphabet = ['Z', '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'];

    $posR = strpos($word, 'R');
    $posC = strpos($word, 'C');

    $row = substr($word, $posR + 1, $posC-1);
    $col = substr($word, $posC + 1);

    if($col <= 25){
        $remainder = $col % 26;
        array_push($indexes, $remainder);
    }
    else{
        while($col > 25){
            $remainder = $col % 26;
            $col = $col / 26;
            array_push($indexes, $remainder);
            if ($col / 26 < 25){
                $col = floor($col);
                array_push($indexes, $col);
            }
        }
    }

    $rereversedIndexes = array_reverse($indexes);
    for ($i = 0; $i < sizeof($indexes); $i++){
        $normal = $normal.$alphabet[$rereversedIndexes[$i]];
    }

    print($normal.$row."\n");
}

function convertToRC($word){
    $rowNum = 0;

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

    for ($i = 0; $i < strlen($word); $i++){
        if(in_array($word[$i], $digits)){
            $index = $i;
            break;
        }
    }

    if($index == 1){
        $index = 2;
    }

    $rowRev = substr($word, 0, $index);
    $col = substr($word, $index);

    $row = strrev($rowRev);

    for($i = strlen($row)-1; $i >= 0; $i--){
        $rowNum += $alphabet[$row[$i]] * pow(26, $i);
    }

    print("R".$col."C".$rowNum."\n");
}

<?php
fscanf(STDIN,"%d",$n);
function IsInt($var)
{
  if(ord($var)>=48&&ord($var)<=57)
    return true;
  else
    return false;
}
function GetInt($var)
{
  $res="";
  for($i=1;$i<strlen($var);$i++)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return $res;
    }
  }
}
function GetInt_D($var)
{
  $res="";
  for($i=strlen($var)-1;$i>=0;$i--)
  {
  //  echo "$i ~~".$var[$i];
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
    //  echo "RES=".$res;
      return strrev($res);
    }
  }
}

$map=array();
$map2=array();
$index=1;
for($i=65;$i<=90;$i++)
{
  $map[chr($i)]=$index;
  $map2[$index]=chr($i);
  $index++;
}
for($i=65;$i<=90;$i++)
{
  for($ii=65;$ii<=90;$ii++)
  {
    $map[chr($i).chr($ii)]=$index;
    $map2[$index]=chr($i).chr($ii);
    $index++;
  }
}
for($i=65;$i<=90;$i++)
{
  for($ii=65;$ii<=90;$ii++)
  {
    for($iii=65;$iii<=90;$iii++)
    {
    $map[chr($i).chr($ii).chr($iii)]=$index;
    $map2[$index]=chr($i).chr($ii).chr($iii);
    $index++;
    }
  }
}

//print_r($map);
//print_r($map2);

while($n--)
{
fscanf(STDIN,"%s",$str);
  //$str=$n==1?"R12C4":"R5C255";
  //echo "::".$str[1];
  if($str[0]=='R'&& IsInt($str[1]))
  {
    // echo "$str is type 1</br>"; R23C55
    // echo GetInt($str);
    // echo "~~~";
    $a=GetInt($str);
    $b=GetInt_D($str);
//    echo $a."~~~".$b;
    echo $map2[$b].$a."\n";

  }
  else {
    $a="";
    for($i=0;$i<strlen($str);$i++)
    {
      if(!IsInt($str[$i]))
      {
        $a.=$str[$i];
      }
      else {
        break;
      }
    }
    $b=GetInt_D($str);
  //  echo "b=$b";
      echo 'R'.$b.'C'.$map[$a]."\n";
  }

}
?>

$fr = fopen("php://stdin", "r");
$n = (int) fgets($fr);
echo $n;
$n = (int) fgets($fr);
echo $n;

<?php
	$data = array();
    fscanf(STDIN, "%d\n", $n);
    for($i=0; $i<$n; $i++) {
    	fscanf(STDIN, "%s\n", $data[$i]);
    	if($data[$i][0] == 'R' && ord($data[$i][1]) >= 48 && ord($data[$i][1]) <= 57) {
    		$column = '';
    		$string = '';
    		$flag = false;
    		for($j = 1; $j < strlen($data[$i]); $j++) {
    			if($data[$i][$j] == 'C') {
    				$flag = true;
    			} else {
    				if(!$flag) {
    					$string .= $data[$i][$j];
    				} else {
    					$column .= $data[$i][$j];
    				}
    			}
    		}
    		$strColumn = '';
    		$column = (int)$column;
    		$cLen = floor($column / 26);

    		for($j = 0; $j < $cLen; $j++) {
    			if($column % 26 != 0) {
	    			$strColumn .= chr($column % 26 + 64);
	    			$column = floor($column / 26);
	    		} else {
	    			$strColumn .= chr($column + 64);
	    		}
    		}
    		$data[$i] = strrev($strColumn) . $string;

    	} else {
    		$column = '';
    		$string = '';
    		for($j = 0; $j<strlen($data[$i]); $j++) {
    			if(ord($data[$i][$j]) >= 65 &&  ord($data[$i][$j]) <= 90) {
    				$column .= $data[$i][$j];
    			} else {
    				$string .= $data[$i][$j];
    			}
    		}

    		$columnNum = 0;
    		for($j = strlen($column) - 1; $j >= 0; $j--) {
    			$columnNum += (ord($column[$j]) - 64) * pow(26, strlen($column)-$j-1);
    		}
    		$data[$i] = 'R' . $string . 'C' . $columnNum;
    	}
    }

    echo implode("\n", $data);
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
foreach ($input as $val) {
    if (preg_match('~^R([0-9]+)C([0-9]+)$~', $val, $matches)) {
        $r = $matches[1];
        $c = $matches[2];
        $cStr = '';
        while ($c > 0) {
            $cStr = chr(64+($c % 26)) . $cStr;
            $c = floor($c / 26);
        }
        echo $cStr . $r . "\n";
    } elseif (preg_match('~^([A-Z]+)([0-9]+)$~', $val, $matches)) {
        $r = $matches[2];
        $cStr = $matches[1];
        $cStrLen = strlen($cStr);
        $c = 0;
        for ($i = 0; $i < $cStrLen; $i ++) {
            $l = substr($cStr, $i, 1);
            $l = ord($l) - 64;
            $c += $l * pow(26, $cStrLen - $i - 1);
        }
        echo 'R' . $r . 'C' . $c . "\n";
    }
}

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$result .= chr(64 + $a % 26);
		$a = floor($a / 26);
	}
	return strrev($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

echo $n;
var_dump($a);

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "\n";
}
echo change($a[$n - 1]);

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = fgets($stdin);

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    } else {
        var_dump($coords);
        preg_match("/^R([0-9]+)C([0-9]+)$/", $coords, $matches);
        var_dump($matches);
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 26) {
        echo to_letter($n);
        $n /= 26;
    }

    echo to_letter($n);

    return strrev(ob_get_clean());
}

/**
 * @param int $n
 *
 * @return string
 */
function to_letter($n) {
    return chr($n % 26 + 64);
}

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%s", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$d = 64 + $a % 26;
		if ($d == 0) {
			$d += 26;
		}
		$result .= chr($d);
		$a = floor($a / 26);
	}
	return ($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "\n";
}
echo change($a[$n - 1]);

<?php

function toAlpha($num){
        $res="";
        while ($num>0)
        {
                $r=($num-1)%26;
                $res = chr($r+65).$res;
                $num = floor(($num-1)/26);
        }
        return $res;
}

function toNum($string){
        $int = 0;
        $len = strlen($string);
        for($i = 0; $i< $len; $i++){
                $int*=26;
                $int += ord($string[$i]) - 64;
        }
        return $int;
}

$file = fscanf(STDIN, "%d\n", $cells);
for($i=0; $i<$cells; $i++){
        fscanf(STDIN, "%s\n", $line);
        if($line[0] == 'R' && $line[1]<10){
                $cPos = strpos($line, 'C', 2);
                if($cPos){
                        print(toAlpha(substr($line, $cPos+1)).substr($line, 1, $cPos-1)."\n");
                }else{
                        print('R'.substr($line, 1)."C18\n");
                }
        }else{
                preg_match('/[0-9]/', $line, $matches, PREG_OFFSET_CAPTURE);
                print('R'.substr($line, $matches[0][1]).'C'.toNum(substr($line, 0, $matches[0][1]))."\n");
        }
}

<?php
function read_sheet($str) {
    if (preg_match("/R(\d+)C(\d+)/",$str,$match)) {
        $sub = $match[2];
        while ($sub > 0) {
            $mod[] = bcmod($sub,26);
            $sub = bcdiv($sub,26);
        }

        $count = count($mod);
        $column = '';
        $tmp = null;
        for ($i =0;$i< $count;$i++) {
            $now = $mod[$i];
            if ($mod[$i] == 0) {
                $tmp = $i;
                $now = 26;
            }

            if ($tmp !== null and bcadd($tmp,1) == $i) {
                if ($now == 0){
                    $now = 26;
                }
                $now = bcsub($now,1);
                if ($now == 0); continue;
            }

            $column .= chr($now+64);
        }
        $column = strrev($column);
        echo $column.$match[1];

    } elseif (preg_match("/([A-Z]+)(\d+)/",$str,$match)) {
        $len = strlen($match[1]);
        $num = 0;       // 字母序列和
        for ($i = 0; $i < $len; $i++) {
            $num = bcadd(bcmul(bcsub(ord($match[1][$i]),64),bcpow(26,bcsub($len,bcadd($i,1)))),$num);
        }
        echo "R".$match[2]."C".$num;
    }
}

$line = 0;
while ($data = fscanf(STDIN,"%s")) {
    if (!$line) {
        $line++;
        continue;
    }
    read_sheet($data[0]);
    echo "\n";
}

<?php

	$first_marker = 0;
	$second_marker = 0;
	function conv2 ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = numToLet($second);
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i-1);
				$second = substr($string, $i-1);
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

	function numToLet ($num){
		$raz = 1;
		$newnum = $num;
		while (($newnum/26)>1.03845) {
			if ((int)$newnum/26 != 27 AND $newnum!=18278) {
			$raz++;
			}
			$newnum /= 26;
		}
		$newnum = $num;
		$res = '';
		for ($i=0;$i<$raz;$i++) {
			$cur = $newnum%26;
			switch ($cur) {
				case 1: $res = 'A'.$res; break;
				case 2: $res = 'B'.$res; break;
				case 3: $res = 'C'.$res; break;
				case 4: $res = 'D'.$res; break;
				case 5: $res = 'E'.$res; break;
				case 6: $res = 'F'.$res; break;
				case 7: $res = 'G'.$res; break;
				case 8: $res = 'H'.$res; break;
				case 9: $res = 'I'.$res; break;
				case 10: $res = 'J'.$res; break;
				case 11: $res = 'K'.$res; break;
				case 12: $res = 'L'.$res; break;
				case 13: $res = 'M'.$res; break;
				case 14: $res = 'N'.$res; break;
				case 15: $res = 'O'.$res; break;
				case 16: $res = 'P'.$res; break;
				case 17: $res = 'Q'.$res; break;
				case 18: $res = 'R'.$res; break;
				case 19: $res = 'S'.$res; break;
				case 20: $res = 'T'.$res; break;
				case 21: $res = 'U'.$res; break;
				case 22: $res = 'V'.$res; break;
				case 23: $res = 'W'.$res; break;
				case 24: $res = 'X'.$res; break;
				case 25: $res = 'Y'.$res; break;
				case 0: $res = 'Z'.$res; break;
			}
			if ($cur==0){
			$newnum = floor($newnum/26)-1;
			}
			else {
			$newnum/=26;
			}
		}
		return $res;
	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
		    $cur = (ord($let[$i])-64);
			if ($i<(strlen($let)-1)) {
			$sum = $sum + $cur*pow(26,(strlen($let)-$i-1));
			}
			else {
			$sum += $cur;
			}
		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php
function number_to_alpha($num) {
  $str = '';
  $num = (int)$num;
  $continue = false;
  do {
    $continue = $num > 26;
    if ($continue) {
      $curr_num = $num % 26;
      $str = chr($curr_num + 64).$str;
      $num = floor($num / 26);
    } else {
      $str = chr($num + 64).$str;
    }
  } while ($continue);
  return $str;
}

function alpha_to_number($str) {
  $parts = str_split($str);
  $num = 0;
  for ($i = 0; $i < count($parts); $i++) {
    $num = $num * 26;
    $num += ord($parts[$i]) - 64;
  }
  return $num;
}

function convert_one($str) {
  $parts = preg_split("/\d+/", $str);
  if ($parts[0] === 'R' && $parts[1] === 'C') {
    // from RXCY
    $numbers = preg_split("/R|C/", $str);
    $row = $numbers[1];
    $col = $numbers[2];
    printf("%s%d", number_to_alpha($col), $row);
  } else {
    // to RXCY
    $col_str = $parts[0];
    $col = alpha_to_number($col_str);
    $row_parts = preg_split("/[A-Z]+/", $str);
    $row = (int)$row_parts[1];
    printf("R%dC%d", $row, $col);
  }
}

fscanf(STDIN, "%d", $n);
for ($i = 1; $i <= $n; $i++) {
  fscanf(STDIN, "%s", $str);
  convert_one($str);
}
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, numToChar($matches[2]).$matches[1].PHP_EOL);
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, 'R'.$matches[2].'C'.charToNum($matches[1]).PHP_EOL);
	}
}

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, numToChar($matches[2]).$matches[1]);
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, 'R'.$matches[2].'C'.charToNum($matches[1])."\n");
	}
}

<?php

$f = STDIN;
$n = fgets($f);

for($i = 0; $i < $n; $i++) {
    $input = fgets($f);

    if(preg_match('/R(\d+)C(\d+)/i', $input, $matches)) {
        $r = $matches[1];
        $c = $matches[2];

        toCR($r, $c);
    } else if(preg_match('/([A-Za-z]+)([0-9]+)/i', $input, $matches)) {

        $r = $matches[2];
        $c = $matches[1];
        toRxCy($r, $c);
    }
}

fclose($f);

function toRxCy($r, $c)
{
    $outR = $r;
    $outC = 0;

    $len = strlen($c);
    $d = 1;

    for($j=$len-1; $j>=0; $j--)
    {
        $outC += (ord($c[$j])-64)*$d;
        $d*=26;
    }

    print_r(sprintf('R%sC%s', $outR, $outC));
}

function toCR($r, $c)
{
    $outR = $r;
    $outC = '';

    while($c)
    {
        $outC = chr(65 + ($c-1)%26) . $outC;
        $c = (integer)(($c - ($c-1)%26)/26);
    }

    print_r(sprintf('%s%s', $outC, $outR));
}

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));

function convertS1($input){
	$nums = ["1","2","3","4","5","6","7","8","9","0"];
	$col ="";
	$col_num =0;
	$row =0;
	$inputs = str_split($input);
	for ($i=0; $i < count($inputs); $i++) {
		if(in_array($inputs[$i], $nums)){
			// echo "AA-".$inputs[$i]."\n";
			$col = substr($input, 0, $i);
			$row = intval(substr($input, $i));
			break;
		}
	}
	$cols = str_split($col);
	for ($i=0; $i < count($cols); $i++) {

		$col_num += ( ((count($cols)-$i-1)*26)*( ord($cols[$i]) - ord("A") +1 ) );
		if($i==count($cols)-1){
			$col_num += ( ord($cols[$i]) - ord("A") +1 ) ;
		}
	}
	return "R{$row}C{$col_num}";

}

function convertS2($input){
	$inputs = explode("C",$input);
	$col =0;
	$col_char ="";
	$row =0;
	$row = intval(str_replace("R", "", $inputs[0]));
	$col = intval($inputs[1]);
	$flag=true;
	while(true){
		if(intval($col/26)<=0){
			$col_char .= chr(($col%26)+64);
			break;
		}else{
			$col_char .= chr(($col/26)+64);
		}

		$col = ($col%26);
		// if(!$flag)break;
		// if(intval($col/26)<=0){
		// 	$flag = false;
		// }
	}
	return "{$col_char}{$row}";
}
$inputs=[];
for ($i=0; $i < $n; $i++) {
	$inputs[] = strval(trim(fgets(STDIN)));

}
for ($i=0; $i < $n; $i++) {
	if($i>0)echo "\n";
	$input = $inputs[$i];
	if (!preg_match('/R(\d+)C(\d+)/',
                $input))
	{
	 	echo convertS1($input);
	}
	else
	{
		echo convertS2($input);
	}

}

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = trim(fgets($stdin));

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    } else {
        var_dump($coords);
        preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches);
        var_dump($matches);
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 26) {
        echo to_letter($n);
        $n /= 26;
    }

    echo to_letter($n);

    return strrev(ob_get_clean());
}

/**
 * @param int $n
 *
 * @return string
 */
function to_letter($n) {
    return chr($n % 26 + 64);
}

<?php

	$first_marker = 0;
	$second_marker = 0;
	function conv2 ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = strrev(numToLet($second));
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i-1);
				$second = substr($string, $i-1);
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

	function numToLet ($num){
		$raz = 1;
		$newnum = $num;
		while (($newnum/26)>1) {
			$raz++;
			$newnum /= 26;
		}
		$newnum = $num;
		$res = '';
		for ($i=0;$i<$raz;$i++) {
			$cur = $newnum%26;
			switch ($cur) {
				case 1: $res = $res.'A'; break;
				case 2: $res = $res.'B'; break;
				case 3: $res = $res.'C'; break;
				case 4: $res = $res.'D'; break;
				case 5: $res = $res.'E'; break;
				case 6: $res = $res.'F'; break;
				case 7: $res = $res.'G'; break;
				case 8: $res = $res.'H'; break;
				case 9: $res = $res.'I'; break;
				case 10: $res = $res.'J'; break;
				case 11: $res = $res.'K'; break;
				case 12: $res = $res.'L'; break;
				case 13: $res = $res.'M'; break;
				case 14: $res = $res.'N'; break;
				case 15: $res = $res.'O'; break;
				case 16: $res = $res.'P'; break;
				case 17: $res = $res.'Q'; break;
				case 18: $res = $res.'R'; break;
				case 19: $res = $res.'S'; break;
				case 20: $res = $res.'T'; break;
				case 21: $res = $res.'U'; break;
				case 22: $res = $res.'V'; break;
				case 23: $res = $res.'W'; break;
				case 24: $res = $res.'X'; break;
				case 25: $res = $res.'Y'; break;
				case 0: $res = $res.'Z'; break;
			}
			$newnum/=26;
		}
		return $res;
	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
		    $cur = (ord($let[$i])-64);
			if ($i<(strlen($let)-1)) {
			$sum = $sum + $cur*(26*(strlen($let)-$i-1));
			}
			else {
			$sum += $cur;
			}
		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));

function convertS1($input){
	$nums = ["1","2","3","4","5","6","7","8","9","0"];
	$col ="";
	$col_num =0;
	$row =0;
	$inputs = str_split($input);
	for ($i=0; $i < count($inputs); $i++) {
		if(in_array($inputs[$i], $nums)){
			// echo "AA-".$inputs[$i]."\n";
			$col = substr($input, 0, $i);
			$row = intval(substr($input, $i));
			break;
		}
	}
	$cols = str_split($col);
	for ($i=0; $i < count($cols); $i++) {

		$col_num += ( pow(26,(count($cols)-$i-1))*( ord($cols[$i]) - ord("A") +1 ) );
		// if($i==count($cols)-1){
		// 	$col_num += ( ord($cols[$i]) - ord("A") +1 ) ;
		// }else{

		// }
	}
	return "R{$row}C{$col_num}";

}

function convertS2($input){
	$inputs = explode("C",$input);
	$col =0;
	$col_char ="";
	$row =0;
	$row = intval(str_replace("R", "", $inputs[0]));
	$col = intval($inputs[1]);
	$flag=true;
	while(true){
		if(intval($col/26)<=0){
			$col_char .= chr(($col%26)+64);
			break;
		}else{
			$col_char .= chr(($col/26)+64);
		}

		$col = ($col%26);
		// if(!$flag)break;
		// if(intval($col/26)<=0){
		// 	$flag = false;
		// }
	}
	return "{$col_char}{$row}";
}
$inputs=[];
for ($i=0; $i < $n; $i++) {
	$inputs[] = strval(trim(fgets(STDIN)));

}
for ($i=0; $i < $n; $i++) {
	if($i>0)echo "\n";
	$input = $inputs[$i];
	if (!preg_match('/R(\d+)C(\d+)/',
                $input))
	{
	 	echo convertS1($input);
	}
	else
	{
		echo convertS2($input);
	}

}

<?php
function read_sheet($str) {
    if (preg_match("/R(\d+)C(\d+)/",$str,$match)) {
        $sub = $match[2];
        while ($sub > 0) {
            $mod[] = bcmod($sub,26);
            $sub = bcdiv($sub,26);
        }

        $count = count($mod);
        $column = '';
        $tmp = [];
        for ($i =0;$i< $count;$i++) {
            $now = $mod[$i];
            if ($mod[$i] == 0) {
                $tmp[$i] = true;
                $now = 26;
            }

            if ($tmp !== null and $tmp[$i-1]) {
                if ($now == 0){
                    $now = 26;
                }
                $now = bcsub($now,1);
                if ($now < 0) {
                    $now = 26 + $now;
                }
                if ($now == 0) {
                    $now = 26;
                    $tmp[$i] = true;
                };
            }

            echo $now."\n";

            $column .= chr($now+64);
        }
        $column = strrev($column);
        return $column.$match[1];

    } elseif (preg_match("/([A-Z]+)(\d+)/",$str,$match)) {
        $len = strlen($match[1]);
        $num = 0;       // 字母序列和
        for ($i = 0; $i < $len; $i++) {
            $num = bcadd(bcmul(bcsub(ord($match[1][$i]),64),bcpow(26,bcsub($len,bcadd($i,1)))),$num);
        }
        return "R".$match[2]."C".$num;
    }
}

$line = 0;
while ($data = fscanf(STDIN,"%s")) {
    if (!$line) {
        $line++;
        continue;
    }
    echo read_sheet($data[0]);
    echo "\n";
}

<?php

$n = 0;

fscanf(STDIN, "%d", $n);

for ($iv = 0; $iv < $n; $iv++) {
    fscanf(STDIN, "%s", $var);

    if(preg_match("/R([0-9]+)C([0-9]+)/", $var, $matches)){
        $new = "";
        mytostr((int)$matches[2], $new);
        print $new.$matches[1]."\n";
    }
    elseif ( preg_match("/([A-Z]+)([0-9]+)/", $var, $matches) ) {
        $new = 0;
        mytoint($matches[1], $new);
        print "R".$matches[2]."C".$new."\n";
    }
}

function mytostr($param, &$result) {
    $result = "";
    if ($param / 26 > 1) {
        $result .= chr(round($param / 26) + ord("A") - 1);
    }
    if ($param % 26 > 0) {
        $result .= chr(round($param % 26) + ord("A") - 1);
    }
}

function mytoint($param, &$result) {
    $result = 0;
    for ($index = 0; $index < strlen($param); $index++) {
        $result += (ord($param[$index]) - ord("A") + 1) * pow(26, (strlen($param) - $index - 1));
    }
}

?>

<?php
/*
In the popular spreadsheets systems (for example, in Excel) the following numeration of
columns is used. The first column has number A, the second — number B, etc. till column
26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB,
column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation
of the column and the row numbers. For example, BC23 is the name for the cell that is in
column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
showing the column and the row numbers respectfully. For instance, R23C55 is the cell
from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and
produce each item written according to the rules of another numeration system.

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

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

Sample test(s)
Input
2
R23C55
BC23

Output
BC23
R23C55
*/
$n = fgets(STDIN);
for ($i = 0; $i < $n; $i++)
    $r[$i] = fgets(STDIN);
/*
$n = 1;
$r[0] = 'R65114C109610';
*/
for ($i = 0; $i < $n; $i++) {
    if (preg_match('"[R][0-9]{1,6}[C][0-9]{1,6}"',$r[$i]) == 1) {
        $s = preg_split('"[RC]"',$r[$i]);

        $s2 = $s[2];
        $d1 = '';
        while ($s2 > 0) {
            $d1 = chr(($s2 - 1) % 26 + 65) . $d1;
            $s2 = floor($s2 / 26);
            //echo "--$s2 $d1\n";
        }
        echo "$d1$s[1]\n";
        //print_r ($s);
    }
    else {
        $l = preg_split('"[0-9]"',$r[$i]);
        $d = preg_split('"[A-Z]"',$r[$i]);

        $l1 = str_split($l[0]);
        $re = 0;
        for ($j = 0; $j < count($l1); $j++) {
            $re = 26 * $re + ord($l1[$j]) - 64;
            //echo "$j $re\n";
        }
        $d1 = intval($d[count($d) - 1]);
        //print_r($l1);
        //print_r($d);
        echo "R$d1" . "C$re\n";
    }
}
?>

<?php
fscanf(STDIN,"%d",$n);
function IsInt($var)
{
  if(ord($var)>=48&&ord($var)<=57)
    return true;
  else
    return false;
}
function GetInt($var)
{
  $res="";
  for($i=1;$i<strlen($var);$i++)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return $res;
    }
  }
}
function GetInt_D($var)
{
  $res="";
  for($i=strlen($var)-1;$i>=0;$i--)
  {
  //  echo "$i ~~".$var[$i];
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
    //  echo "RES=".$res;
      return strrev($res);
    }
  }
}

$map=array();
$map2=array();
$index=1;
for($i=65;$i<=90;$i++)
{
  $map[chr($i)]=$index;
  $map2[$index]=chr($i);
  $index++;
}
for($i=65;$i<=90;$i++)
{
  for($ii=65;$ii<=90;$ii++)
  {
    $map[chr($i).chr($ii)]=$index;
    $map2[$index]=chr($i).chr($ii);
    $index++;
  }
}

//print_r($map);
//print_r($map2);

while($n--)
{
fscanf(STDIN,"%s",$str);
  //$str=$n==1?"R12C4":"R5C255";
  //echo "::".$str[1];
  if($str[0]=='R'&& IsInt($str[1]))
  {
    // echo "$str is type 1
"; R23C55
    // echo GetInt($str);
    // echo "~~~";
    $a=GetInt($str);
    $b=GetInt_D($str);
//    echo $a."~~~".$b;
    echo $map2[$b].$a."\n";

  }
  else {
    // echo "$str is type 2
";BC23
    $a="";
    for($i=0;$i<strlen($str);$i++)
    {
      if(!IsInt($str[$i]))
      {
        $a.=$str[$i];
      }
      else {
        break;
      }
    }
    $b=GetInt_D($str);
  //  echo "b=$b";
      echo 'R'.$b.'C'.$map[$a]."\n";
  }

}
?>

<?php

fscanf(STDIN, "%s", $n);
print $n;
fscanf(STDIN, "%s", $s);
print $s;

<?php
error_reporting("off");
//1B: Spreadsheets
//Lesson of the day: Don't freak out about local variables leaking. They're going to stay local. so just reuse the same name.
//Reusing those same names prevents creation of outlandish (and not descriptive) variable names, such as "yay", "oki", "yeah", "yayy", "yah", "ohyeah", "nodnod", etc.
//$array = array("ZZ21", "XZ250", "R98C688", "R785221C773428");
$n = trim(fgets(STDIN)); //$n = 4;
$shiftover = array(
    "0" => "0",
    "A" => "1",
    "B" => "2",
    "C" => "3",
    "D" => "4",
    "E" => "5",
    "F" => "6",
    "G" => "7",
    "H" => "8",
    "I" => "9",
    "J" => "A",
    "K" => "B",
    "L" => "C",
    "M" => "D",
    "N" => "E",
    "O" => "F",
    "P" => "G",
    "Q" => "H",
    "R" => "I",
    "S" => "J",
    "T" => "K",
    "U" => "L",
    "V" => "M",
    "W" => "N",
    "X" => "O",
    "Y" => "P",
    "Z" => "Q");

$letters = array(
    "0" => "0",
    "1" => "1",
    "2" => "2",
    "3" => "3",
    "4" => "4",
    "5" => "5",
    "6" => "6",
    "7" => "7",
    "8" => "8",
    "9" => "9",
    "10" => "A",
    "11" => "B",
    "12" => "C",
    "13" => "D",
    "14" => "E",
    "15" => "F",
    "16" => "G",
    "17" => "H",
    "18" => "I",
    "19" => "J",
    "20" => "K",
    "21" => "L",
    "22" => "M",
    "23" => "N",
    "24" => "O",
    "25" => "P",
    "26" => "Q");

$newcells = array();

function mybase26($number) { //something funky that takes out the zeros and replaces them with "Z"s (non-existent in base 26) and decrements the next highest place value
    //coming from base 10
    global $letters;
    $places = array();
    $places[4] = 0;
    $places[3] = 0;
    $places[2] = 0;
    $places[1] = 0;
    $places[0] = 0;
    //the number can't have a fives place since it's smaller than 10^6
    //yes we're brute forcing here
    if ($number > 456976) { //notice how we're not using >=, this is so that we don't reach a zero and we can use the Zs. In a normal conversion function this would take out allll the 456976s possible, here, we leave one, if there's one left.
        do {
            $number = $number - 456976; //26^4
            $places[4]++;
        } while ($number > 456976);
    }
    if ($number > 17576) {
        do {
            $number = $number - 17576; //26^3
            $places[3]++;
        } while ($number > 17576);
    }
    if ($number > 676) {
        do {
            $number = $number - 676;
            $places[2]++;
        } while ($number > 676);
    }
    if ($number > 26) {
        do {
            $number = $number - 26;
            $places[1]++;
        } while ($number > 26);
    }
    if ($number <= 26) { //because we close this baby out and take it all home in the last place, we use <= here.
        $places[0] = $number;
    }

    //okay okay I know I'm being inefficient with my loops here
    if ($places[3] == 0 && $places[4] > 0) {
        $places[4]--;
        $places[3] = 26;
    }
    if ($places[2] == 0 && $places[3] > 0) {
        $places[3]--;
        $places[2] = 26;
    }
    if ($places[1] == 0 && $places[2] > 0) {
        $places[2]--;
        $places[1] = 26;
    }
    if ($places[0] == 0 && $places[1] > 0) {
        $places[1]--;
        $places[0] = 26;
    }

    //now we have the place values; just get them into letters if bigger than 9.
    $places[4] = $letters[$places[4]];
    $places[3] = $letters[$places[3]];
    $places[2] = $letters[$places[2]];
    $places[1] = $letters[$places[1]];
    $places[0] = $letters[$places[0]];

    return ltrim($places[4].$places[3].$places[2].$places[1].$places[0], "0");
}

function mybase10($number) { //with an array that includes Z = 26
    //from base 26
    global $letters;
    $explode = str_split($number);
    $power = 0; //of 26
    $sum = 0; //result

    foreach ($explode as $key => $value) { //convert from A to 10, for example
        $explode[$key] = array_search($value, $letters);
    }

    //tricky way of reversing number to start with zeros place and then increase
    $reversedAndReindexed = array_values(array_reverse($explode));
    $places = count($reversedAndReindexed);

    for ($i = 0; $i < $places; $i++) {
        $sum = $sum + (pow(26, $power) * $reversedAndReindexed[$i]); //learn something new everyday. pow is the base to exponent function. And to think I guessed it from my text editor.
        $power++;
    }

    return $sum;
}

function numbertoletter($number) {
    global $shiftover;
    $base26 = str_split(mybase26($number)); //get from base 10 to base 26
    $shift = "";
    foreach ($base26 as $value) { //now shift all the characters over to start at A instead of 1
        $shift .= array_search($value, $shiftover);
    }
    return $shift;
}

function lettertonumber($letter) {
    global $shiftover;
    $explode = str_split($letter);
    $shift = "";
    foreach ($explode as $value) { //shift all the characters over to start at 1 instead of A
        $shift .= $shiftover[$value];
    }

    $base10 = mybase10($shift);
    return $base10;
}

//main(), if you will
for ($i = 0; $i < $n; $i++) {
    $cell = trim(fgets(STDIN)); //$cell = $array[$i];
    if (preg_match("/R([0-9]+)C([0-9]+)/", $cell, $matches) == TRUE) {
        $matches[2] = numbertoletter($matches[2]);
        $newcells[] = $matches[2].$matches[1];
    } else {
        preg_match("/([A-Z]+)([0-9]+)/", $cell, $matches);
        $matches[1] = lettertonumber($matches[1]);
        $newcells[] = "R".$matches[2]."C".$matches[1];
    }
}

foreach ($newcells as $value) {
    echo $value."\n";
}
?>

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = fgets($stdin);

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    } else {
        preg_match("/^R(?<row>[0-9]+)C(?<column>[0-9]+)$/", $coords, $matches);
        var_dump($matches);
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 26) {
        echo to_letter($n);
        $n /= 26;
    }

    echo to_letter($n);

    return strrev(ob_get_clean());
}

/**
 * @param int $n
 *
 * @return string
 */
function to_letter($n) {
    return chr($n % 26 + 64);
}

<?php

	$first_marker = 0;
	$second_marker = 0;
	function conv2 ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = strrev(numToLet($second));
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i-1);
				$second = substr($string, $i-1);
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

	function numToLet ($num){
		$raz = 1;
		$newnum = $num;
		while (($newnum/26)>1) {
			$raz++;
			$newnum /= 26;
		}
		$newnum = $num;
		$res = '';
		for ($i=0;$i<$raz;$i++) {
			$cur = $newnum%26;
			switch ($cur) {
				case 1: $res = 'A'.$res; break;
				case 2: $res = 'B'.$res; break;
				case 3: $res = 'C'.$res; break;
				case 4: $res = 'D'.$res; break;
				case 5: $res = 'E'.$res; break;
				case 6: $res = 'F'.$res; break;
				case 7: $res = 'G'.$res; break;
				case 8: $res = 'H'.$res; break;
				case 9: $res = 'I'.$res; break;
				case 10: $res = 'J'.$res; break;
				case 11: $res = 'K'.$res; break;
				case 12: $res = 'L'.$res; break;
				case 13: $res = 'M'.$res; break;
				case 14: $res = 'N'.$res; break;
				case 15: $res = 'O'.$res; break;
				case 16: $res = 'P'.$res; break;
				case 17: $res = 'Q'.$res; break;
				case 18: $res = 'R'.$res; break;
				case 19: $res = 'S'.$res; break;
				case 20: $res = 'T'.$res; break;
				case 21: $res = 'U'.$res; break;
				case 22: $res = 'V'.$res; break;
				case 23: $res = 'W'.$res; break;
				case 24: $res = 'X'.$res; break;
				case 25: $res = 'Y'.$res; break;
				case 0: $res = 'Z'.$res; break;
			}
			if ($cur==0){
			$newnum = floor($newnum/26)-1;
			}
			else {
			(int)$newnum/=26;
			}
		}
		return $res;
	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
		    $cur = (ord($let[$i])-64);
			if ($i<(strlen($let)-1)) {
			$sum = $sum + $cur*(26*(strlen($let)-$i-1));
			}
			else {
			$sum += $cur;
			}
		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php

fscanf(STDIN, "%d", $n);
$a = array();

for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%d", $a[$i]);
}

function tach($str) {
	$result = array();

	$pattern = '/[0-9]/';
	preg_match($pattern, $str, $matches);
	$a1 = strpos($str, $matches[0]);
	$result[] = substr($str, 0, $a1);
	$str = substr($str, $a1);

	$pattern = '/[A-Z]/';
	preg_match($pattern, $str, $matches);
	if (count($matches) > 0) {
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$str = substr($str, $a1);
		$pattern = '/[0-9]/';
		preg_match($pattern, $str, $matches);
		$a1 = strpos($str, $matches[0]);
		$result[] = substr($str, 0, $a1);
		$result[] = substr($str, $a1);
	} else {
		$result[] = $str;
	}
	return $result;
}

function changeSTN($a) {
	$leng = strlen($a);
	$result = 0;
	for ($i = 0; $i < $leng; $i++) {
		$result += (ord($a[$i]) - 64) * pow(26, $leng - 1 - $i);
	}
	return $result;
}

function changeNTS($a) {
	$result = "";
	while ($a > 0) {
		$result .= chr(64 + $a % 26);
		$a = floor($a / 26);
	}
	return strrev($result);
}

function change($str) {
	$str = tach($str);
	if (count($str) == 2) {
		$result = "R" . $str[1];
		$result .= "C" . changeSTN($str[0]);
	} else {
		$result = changeNTS((int)$str[3]);
		$result .= $str[1];
	}
	return $result;
}

var_dump($a);

for ($i = 0; $i < $n - 1; $i++) {
	echo change($a[$i]) . "\n";
}
echo change($a[$n - 1]);

<?php
    fscanf(STDIN, "%d\n", $n);
    for ($i = 0; $i < $n; $i++) {
        fscanf(STDIN, "%s\n", $coords);
        $coords = str_split($coords);
        $letters = array();
        $digits = array();
        $RXCY = 0;
        while (count($coords)) {
            $char = array_shift($coords);
            if (is_numeric($char)) {
                $digits[$RXCY] .= $char;
            } elseif(isset($digits[0]) && !$RXCY) {
                $RXCY = 1;
                $letters[$RXCY] .= $char;
            } else {
                $letters[$RXCY] .= $char;
            }
        }

        if ($RXCY) {
            $col = $digits[1];
            $colCode = '';
            while ($col > 26) {
                $letNum = floor($col / 26);
                $colCode .= chr(64 + $letNum);
                $col = $col % 26;
            }
            if ($col > 0) {
                $colCode .= chr(64 + $col);
            }
            $resultCode = $colCode . $digits[0];
        } else {
            $colArray = str_split($letters[0]);
            $colNum = 0;
            $power = 0;
            while ($let = array_pop($colArray)) {
                $colNum += (ord($let) - 64) * pow(26, $power++);
            }
            $resultCode = 'R' . $digits[0] . 'C' . $colNum;
        }
        echo "$resultCode\n";
    }
?>

<?php
/**
 * 1/B/main.php
 *
 * Created by capncanuck on 31/10/16 12:11 PM
 * for codeforces
 *
 * B. Spreadsheets
 *
 * @time_limit   : 10 seconds
 * @memory_limit : 64 MB
 * @input        : stdin
 * @output       : stdout
 *
 * In the popular spreadsheets systems (for example, in Excel)
 * the following numeration of columns is used.
 *      The first column has number A, the second — number B, etc. till column 26 that is marked by Z.
 *      Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ.
 *      After ZZ there follow three-letter numbers, etc.
 *
 *      The rows are marked by integer numbers starting with 1.
 *      The cell name is the concatenation of the column and the row numbers.
 *      For example, BC23 is the name for the cell that is in column 55, row 23.
 *
 * Sometimes another numeration system is used: RXCY, where X and Y are integer numbers,
 * showing the column and the row numbers respectfully.
 * For instance, R23C55 is the cell from the previous example.
 *
 * Your task is to write a program that reads the given sequence of cell coordinates
 * and produce each item written according to the rules of another numeration system.
 *
 * Input
 *      The first line of the input contains integer number n (1 ≤ n ≤ 105),
 *      the number of coordinates in the test.
 *      Then there follows n lines, each of them contains coordinates.
 *      All of the coordinates are correct,
 *      there are no cells with the column and/or the row numbers larger than 106.
 *
 * Output
 *      Write n lines, each line should contain a cell coordinates in the other numeration system.
 */

$stdin = fopen("php://stdin", "r");
$n = fgets($stdin);

for ($i = 0; $i < $n; $i++) {
    $coords = fgets($stdin);

    // Excel system to RXCY system
    if (preg_match("/^(?<letter_column>[[:upper:]]+)(?<row>[[:digit:]]+)$/", $coords, $matches)) {
        echo "R";
        echo $matches["row"];
        echo "C";
        echo to_numbers($matches["letter_column"]);
    } // RXCY system to Excel system
    elseif (preg_match("/^R(?<row>[[:digit:]]+)C(?<column>[[:digit:]]+)$/", $coords, $matches)) {
        echo to_letters(intval($matches["column"]));
        echo $matches["row"];
    } else {
        echo "hi";
    }

    if ($i < $n - 1) {
        echo PHP_EOL;
    }
}

/**
 * @param string $letters
 *
 * @return int $letters represented as a number
 */
function to_numbers($letters) {
    return array_reduce(str_split($letters), function($sum, $letter) {
        return $sum * 26 + ord($letter) - 64;
    });
}

/**
 * @param int $n
 *
 * @return string $n represented with letters
 */
function to_letters($n) {
    ob_start();

    while ($n > 26) {
        echo to_letter($n);
        $n /= 26;
    }

    echo to_letter($n);

    return strrev(ob_get_clean());
}

/**
 * @param int $n
 *
 * @return string
 */
function to_letter($n) {
    return chr($n % 26 + 64);
}

<?php
function read_sheet($str) {
    if (preg_match("/R(\d+)C(\d+)/",$str,$match)) {
        $sub = $match[2];
        while ($sub > 0) {
            $mod[] = bcmod($sub,26);
            $sub = bcdiv($sub,26);
        }

        $count = count($mod);
        $column = '';
        $tmp = null;
        for ($i =0;$i< $count;$i++) {
            $now = $mod[$i];
            if ($mod[$i] == 0) {
                $tmp = $i;
                $now = 26;
            }

            if ($tmp !== null and bcadd($tmp,1) == $i) {
                $now = bcsub($now,1);
            }

            $column .= chr($now+64);
        }
        $column = strrev($column);
        echo $column.$match[1];

    } elseif (preg_match("/([A-Z]+)(\d+)/",$str,$match)) {
        $len = strlen($match[1]);
        $num = 0;       // 字母序列和
        for ($i = 0; $i < $len; $i++) {
            $num = bcadd(bcmul(bcsub(ord($match[1][$i]),64),bcpow(26,bcsub($len,bcadd($i,1)))),$num);
        }
        echo "R".$match[2]."C".$num;
    }
}

$line = 0;
while ($data = fscanf(STDIN,"%s")) {
    if (!$line) {
        $line++;
        continue;
    }
    read_sheet($data[0]);

}

<?php
fscanf(STDIN,"%d",$n);
function IsInt($var)
{
  if(ord($var)>=48&&ord($var)<=57)
    return true;
  else
    return false;
}
function IsType1($var)
{
  $res=false;;
  for($i=1;$i<strlen($var);$i++)
  {
    if('C'==($var[$i]))
    {
      $res=true;
      break;
    }
  }
  return $res;
}
function GetInt($var)
{
  $res="";
  for($i=1;$i<strlen($var);$i++)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return $res;
    }
  }
}
function GetInt_D($var)
{
  $res="";
  for($i=strlen($var)-1;$i>=0;$i--)
  {
    if(IsInt($var[$i]))
    {
      $res.=$var[$i];
    }
    else {
      return strrev($res);
    }
  }
}

function conversion_int($var)
{
  $res="";
  while($var>26)
  {
    if($var%26!=0)
    $res.=chr(64+$var%26);
    else {
      $res.='Z';
    }
    $var=($var-$var%26)/26;
  }
  if($var!=0)
  $res.=chr(64+$var);
  return strrev($res);
}
function conversion_str($var)
{
  $res=0;
  for($i=strlen($var)-1;$i>=0;$i--)
  {
    $temp=1;
    for($j=strlen($var)-1;$j>$i;$j--)
    {
      $temp*=26;
    }
    if($var[$i]!='Z')
    $res+=(ord($var[$i])-64)*$temp;
  }
  return $res;
}
while($n--)
{
fscanf(STDIN,"%s",$str);
  if($str[0]=='R'&& IsInt($str[1]) && IsType1($str))
  {
    $a=GetInt($str);
    $b=GetInt_D($str);
    echo conversion_int($b).$a."\n";
  }
  else {
    $a="";
    for($i=0;$i<strlen($str);$i++)
    {
      if(!IsInt($str[$i]))
      {
        $a.=$str[$i];
      }
      else {
        break;
      }
    }
    $b=GetInt_D($str);
      echo 'R'.$b.'C'.conversion_str($a)."\n";

  }
}
?>

<?php

	$first_marker = 0;
	$second_marker = 0;
	function conv2 ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$first = substr($string, 1, $i-1);
					$second = substr($string, $i+1);
				}
			}
		}
		$second = numToLet($second);
		$res = $second.$first;
		return $res;

	}

	function conv ($string) {
		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first = substr($string, 0, $i-1);
				$second = substr($string, $i-1);
			}
		}
		$first = letToNum($first);
		$res = 'R'.$second.'C'.$first;
		return $res;
	}

	function detect ($string) {

		for ($i=0;$i<strlen($string);$i++) {
			if (ord($string[$i])>47 AND ord($string[$i])<58) {
				$first_marker = 1;
			}
			else {
				if ($first_marker == 1) {
					$second_marker = 1;
				}
			}
		}
		if ($second_marker == 1) {
			return conv2($string);
		}
		else {
			return conv($string);
		}

	}

	function numToLet ($num){
		$raz = 1;
		$newnum = $num;
		while (($newnum/26)>1.0385) {
			$raz++;
			$newnum /= 26;
		}
		$newnum = $num;
		$res = '';
		for ($i=0;$i<$raz;$i++) {
			$cur = $newnum%26;
			switch ($cur) {
				case 1: $res = 'A'.$res; break;
				case 2: $res = 'B'.$res; break;
				case 3: $res = 'C'.$res; break;
				case 4: $res = 'D'.$res; break;
				case 5: $res = 'E'.$res; break;
				case 6: $res = 'F'.$res; break;
				case 7: $res = 'G'.$res; break;
				case 8: $res = 'H'.$res; break;
				case 9: $res = 'I'.$res; break;
				case 10: $res = 'J'.$res; break;
				case 11: $res = 'K'.$res; break;
				case 12: $res = 'L'.$res; break;
				case 13: $res = 'M'.$res; break;
				case 14: $res = 'N'.$res; break;
				case 15: $res = 'O'.$res; break;
				case 16: $res = 'P'.$res; break;
				case 17: $res = 'Q'.$res; break;
				case 18: $res = 'R'.$res; break;
				case 19: $res = 'S'.$res; break;
				case 20: $res = 'T'.$res; break;
				case 21: $res = 'U'.$res; break;
				case 22: $res = 'V'.$res; break;
				case 23: $res = 'W'.$res; break;
				case 24: $res = 'X'.$res; break;
				case 25: $res = 'Y'.$res; break;
				case 0: $res = 'Z'.$res; break;
			}
			if ($cur==0){
			$newnum = floor($newnum/26)-1;
			}
			else {
			$newnum/=26;
			}
		}
		return $res;
	}

	function letToNum ($let){
		$sum = 0;
		for ($i=0;$i<strlen($let);$i++) {
		    $cur = (ord($let[$i])-64);
			if ($i<(strlen($let)-1)) {
			$sum = $sum + $cur*pow(26,(strlen($let)-$i-1));
			}
			else {
			$sum += $cur;
			}
		}
		return $sum;
	}

	fscanf(STDIN,"%d\n",$n);
	for ($i = 0;$i<$n;$i++) {
		fscanf(STDIN,"%s\n",$line);
		print(detect($line)."\n");

	}

	?>

<?php
function read_sheet($str) {
    if (preg_match("/R(\d+)C(\d+)/",$str,$match)) {
        $sub = $match[2];
        while ($sub > 0) {
            $mod[] = bcmod($sub,26);
            $sub = bcdiv($sub,26);
        }

        $count = count($mod);
        $column = '';
        $tmp = null;
        for ($i =0;$i< $count;$i++) {
            $now = $mod[$i];
            if ($mod[$i] == 0) {
                $tmp = $i;
                $now = 26;
            }

            if ($tmp !== null and bcadd($tmp,1) == $i) {
                if ($now == 0){
                    $now = 26;
                }
                $now = bcsub($now,1);
            }

            $column .= chr($now+64);
        }
        $column = strrev($column);
        echo $column.$match[1];

    } elseif (preg_match("/([A-Z]+)(\d+)/",$str,$match)) {
        $len = strlen($match[1]);
        $num = 0;       // 字母序列和
        for ($i = 0; $i < $len; $i++) {
            $num = bcadd(bcmul(bcsub(ord($match[1][$i]),64),bcpow(26,bcsub($len,bcadd($i,1)))),$num);
        }
        echo "R".$match[2]."C".$num;
    }
}

$line = 0;
while ($data = fscanf(STDIN,"%s")) {
    if (!$line) {
        $line++;
        continue;
    }
    read_sheet($data[0]);
    echo "\n";
}

<?php

$n = 0;

fscanf(STDIN, "%d", $n);

for ($iv = 0; $iv < $n; $iv++) {
    fscanf(STDIN, "%s", $var);

    if(preg_match("/R([0-9]+)C([0-9]+)/", $var, $matches)){
        $new = "";
        mytostr((int)$matches[2], $new);
        print $new.$matches[1]."\n";
    }
    elseif ( preg_match("/([A-Z]+)([0-9]+)/", $var, $matches) ) {
        $new = 0;
        mytoint($matches[1], $new);
        print "R".$matches[2]."C".$new."\n";
    }
}

function mytostr($param, &$result) {
    $result = "";

    while($param > 1)
    {
        $t = $param % 26;
        $result = chr($t + ord("A") - 1) . $result;
        $param = floor($param / 26);
    }

    //R98C688
}

function mytoint($param, &$result) {
    $result = 0;
    for ($index = 0; $index < strlen($param); $index++) {
        $result += (ord($param[$index]) - ord("A") + 1) * pow(26, (strlen($param) - $index - 1));
    }
}

?>

<?php
# 1B
CONST LETTERS = 'ZABCDEFGHIJKLMNOPQRSTUVWXYZ';
function zz2rc($column, $row) {
    $columnNumber = 0;
    for ($i = strlen($column) - 1, $j = 0; $i >=0; $i--, $j++) {
        $pos = strpos(LETTERS, $column[$i], 1);
        $columnNumber += $pos * (26 ** $j);
    }
    return 'R' . $row . 'C' . $columnNumber;
}

function rc2zz($column, $row) {
    $columnNumber = '';
    while ($column / 26 > 1) {
        $floor = (int)floor($column / 26);
        $mod = $column % 26;
        $columnNumber .= LETTERS[$mod];
        $column = $floor;
    }
    $ost = $column % 26;
    $columnNumber .= LETTERS[$ost];
    return strrev($columnNumber) . $row;
}

$n = fscanf(STDIN, '%u');
while ($row = trim(fgets(STDIN))) {
    if (preg_match('~R(\d+)C(\d+)~', $row, $match)) {
        echo rc2zz($match[2], $match[1]);
    } elseif(preg_match('~([A-Z]+)(\d+)~i', $row, $match)) {
        echo zz2rc($match[1], $match[2]);
    }
    echo PHP_EOL;
}

<?php
$n = readline();
$spreadSheetArray = [];
for ($i = 0; $i < $n; $i++){
    $temp = readline();
    array_push($spreadSheetArray, $temp);
}

for ($i = 0; $i < count($spreadSheetArray); $i++){
    if (isRCNotation($spreadSheetArray[$i])){
        convertToNormal($spreadSheetArray[$i]);
    }
    else{
        convertToRC($spreadSheetArray[$i]);
    }
}

function isRCNotation($value){
    $numberReached = false;
    $RCNotation = false;
    $digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

    for ($i = 0; $i < strlen($value); $i++){
        if (in_array($value[$i], $digits)){
            $numberReached = true;
        }
        if ($numberReached){
            if (!in_array($value[$i], $digits)){
                $RCNotation = true;
                break;
            }
        }
    }

    return $RCNotation;
}

function convertToNormal($word){
    $normal = "";
    $indexes = array();
    $alphabet = ['Z', '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'];

    $posR = strpos($word, 'R');
    $posC = strpos($word, 'C');

    $row = substr($word, $posR + 1, strlen($word)-$posC-1);
    $col = substr($word, $posC + 1);

    if($col <= 25){
        $remainder = $col % 26;
        array_push($indexes, $remainder);
    }
    else{
        while($col > 25){
            $remainder = $col % 26;
            $col = $col / 26;
            array_push($indexes, $remainder);
            if ($col / 26 < 25){
                $col = floor($col);
                array_push($indexes, $col);
            }
        }
    }

    $rereversedIndexes = array_reverse($indexes);
    for ($i = 0; $i < sizeof($indexes); $i++){
        $normal = $normal.$alphabet[$rereversedIndexes[$i]];
    }

    print($normal.$row."\n");
}

function convertToRC($word){
    $rowNum = 0;

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

    for ($i = 0; $i < strlen($word); $i++){
        if(in_array($word[$i], $digits)){
            $index = $i;
        }
    }

    if($index == 1){
        $index = 2;
    }

    $rowRev = substr($word, 0, $index-1);
    $col = substr($word, $index-1);

    $row = strrev($rowRev);

    for($i = strlen($row)-1; $i >= 0; $i--){
        $rowNum += $alphabet[$row[$i]] * pow(26, $i);
    }

    print("R".$col."C".$rowNum."\n");
}

<?php

$f = STDIN;
$n = fgets($f);

for($i = 0; $i < $n; $i++) {
    $input = fgets($f);

    if(preg_match('/R(\d+)C(\d+)/i', $input, $matches)) {
        $r = $matches[1];
        $c = $matches[2];

        toCR($r, $c);
    } else if(preg_match('/([A-Za-z]+)([0-9]+)/i', $input, $matches)) {

        $r = $matches[2];
        $c = $matches[1];
        toRxCy($r, $c);
    }
}

fclose($f);

function toRxCy($r, $c)
{
    $outR = $r;
    $outC = 0;

    $len = strlen($c);
    $d = 1;

    for($j=$len-1; $j>=0; $j--)
    {
        $outC += (ord($c[$j])-64)*$d;
        $d*=26;
    }

    printf('R%sC%s\n', $outR, $outC);
}

function toCR($r, $c)
{
    $outR = $r;
    $outC = '';

    while($c)
    {
        $outC = chr(65 + ($c-1)%26) . $outC;
        $c = (integer)(($c - ($c-1)%26)/26);
    }

    printf('%s%s\n', $outC, $outR);
}

<?php
	$data = array();
    fscanf(STDIN, "%d\n", $n);
    for($i=0; $i<$n; $i++) {
    	fscanf(STDIN, "%s\n", $data[$i]);
    	if($data[$i][0] == 'R' && ord($data[$i][1]) >= 48 && ord($data[$i][1]) <= 57) {
    		$column = '';
    		$string = '';
    		$flag = false;
    		for($j = 1; $j < strlen($data[$i]); $j++) {
    			if($data[$i][$j] == 'C') {
    				$flag = true;
    			} else {
    				if(!$flag) {
    					$string .= $data[$i][$j];
    				} else {
    					$column .= $data[$i][$j];
    				}
    			}
    		}
    		$strColumn = '';
    		$column = (int)$column;

    		do {
    			if($column % 26 != 0) {
	    			$strColumn .= chr($column % 26 + 64);
	    			$column = floor($column / 26);
	    		} else {
	    			$strColumn .= chr($column + 64);
	    		}
    		} while($column % 26 != 0);

    		$data[$i] = strrev($strColumn) . $string;

    	} else {
    		$column = '';
    		$string = '';
    		for($j = 0; $j<strlen($data[$i]); $j++) {
    			if(ord($data[$i][$j]) >= 65 &&  ord($data[$i][$j]) <= 90) {
    				$column .= $data[$i][$j];
    			} else {
    				$string .= $data[$i][$j];
    			}
    		}

    		$columnNum = 0;
    		for($j = strlen($column) - 1; $j >= 0; $j--) {
    			$columnNum += (ord($column[$j]) - 64) * pow(26, strlen($column)-$j-1);
    		}
    		$data[$i] = 'R' . $string . 'C' . $columnNum;
    	}
    }
    echo "\n\n";
    echo implode("\n", $data);
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, numToChar($matches[2]).$matches[1].PHP_EOL);
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		fprintf($fw, 'R'.$matches[2].'C'.charToNum($matches[1]).PHP_EOL);
	}
}
?>

<?php
$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

function numToChar($num) {
	if ($num <= 26) {
		return ($num == 0) ? chr(90) : chr($num + 64);
	} else {
		return numToChar(ceil($num / 26) - 1).numToChar($num % 26);
	}
}

function charToNum($char) {
	if (strlen($char) == 1) {
		return ord($char) - 64;
	} else {
		return charToNum(substr($char, -1, 1))
			+ charToNum(substr($char, 0, -1)) * 26;
	}
}

while(($line = fgets($fr)) !== false) {
	if (preg_match("/^R([0-9]+)C([0-9]+)$/", $line, $matches) == 1) {
		echo numToChar($matches[2]).$matches[1].PHP_EOL;
	} elseif (preg_match("/^([A-Z]+)([0-9]+)$/", $line, $matches) == 1) {
		echo 'R'.$matches[2].'C'.charToNum($matches[1]).PHP_EOL;
	}
}
?>

<?php
function convertRCtoCR($cell){
    $st = preg_match('/^R([0-9]+)C([0-9]+)$/', $cell, $matches);
    $row = $matches[1]; // not modified
    $column = $matches[2];
    $str = ""; //character representation of column

    while( $column%26 > 0){
        $char = $column%26;
        $column = intval($column/26);
        $str = chr($char+64) . $str;
    }
    return $str.$row;
}

function convertCRtoRC($cell){
    $st = preg_match('/^([A-Z]+)([0-9]+)$/', $cell, $matches);
    $column = $matches[1];
    $row = $matches[2]; //not modified
    $chs = str_split($column);
    $count = strlen($column);
    $column = 0;
    foreach($chs as $ch){
        $column += (ord($ch) - 64) * pow(26, $count -1);
        $count--;
    }
    return 'R' . $row . 'C' . $column;
}

function convert($cell){
    $type = preg_match('/^R[0-9]+C[0-9]+$/', $cell, $matches);
    if($type === 1){
        return convertRCtoCR($cell);
    }

    return convertCRtoRC($cell);
}

$dir = fopen("php://stdin", 'r');
$cells = stream_get_contents($dir);

$cells = explode("\n", $cells);
for($i=1;$i<=$cells[0];$i++){
    echo convert($cells[$i])."\n";
}
?>

<?php

$n = 0;

fscanf(STDIN, "%d", $n);

for ($iv = 0; $iv < $n; $iv++) {
    fscanf(STDIN, "%s", $var);

    if(preg_match("/R([0-9]+)C([0-9]+)/", $var, $matches)){
        $new = "";
        mytostr((int)$matches[2], $new);
        print $new.$matches[1]."\n";
    }
    elseif ( preg_match("/([A-Z]+)([0-9]+)/", $var, $matches) ) {
        $new = 0;
        mytoint($matches[1], $new);
        print "R".$matches[2]."C".$new."\n";
    }
}

function mytostr($param, &$result) {
    $result = "";
    if ($param / 26 > 1) {
        $result .= chr(round($param / 26) + ord("A") - 1);
    }
    if ($param % 26 > 0) {
        $result .= chr(round($param % 26) + ord("A") - 1);
    }
}

function mytoint($param, &$result) {
    $result = 0;
    for ($index = 0; $index < strlen($param); $index++) {
        $result += (ord($param[$index]) - ord("A") + 1) * pow(26, (strlen($param) - $index - 1));
    }
}

?>