#! /usr/bin/perl -wl
#------------------------------------------------
# Author:    vj
# Created:   Thu Oct 25 21:02:27 IST 2012
# File Name: a.pl
# USAGE:
#       a.pl
#
#
#------------------------------------------------
use List::Util qw(first max maxstr min minstr reduce shuffle sum);
chomp (my $n = <STDIN>);
my %times;
my $buf;
while ($n--) {
  chomp ($buf = <STDIN>);
  $times{$buf}++;
}
print &max(values %times);

#!/usr/bin/perl -w

use List::Util qw(max);
use strict;

my %times = ();
chomp(my $n = <>);
for (1 .. $n) {
	chomp($_ = <>);
	++$times{$_};
}
my $res = max values %times;
print "$res\n";

use List::Util 'max';for(<>){++$_{$_}}print max values%_

use strict;
use warnings;

my $n = <STDIN>;
my %h = ();
for (1 .. $n) {
  $_ = <STDIN>;
  ++$h{$_};
}
my $m = 0;
for (values %h) {
  $m = $_ if $_ > $m;
}
print "$m\n";

#!perl -n
use List::Util 'max';
INIT{$_=<>}++$_{$_};END{print max values%_}

#!perl -n
use List::Util 'max';
BEGIN{$_='1'}++$_{$_};END{print max values%_}

#!perl -n
use List::Util 'max';
END{print max values%_}++$_{$_}

use strict;
use warnings;
use List::Util 'max';

my $n = <STDIN>;
my %h = ();
for (1 .. $n) {
  $_ = <STDIN>;
  ++$h{$_};
}
my $m = 0;
for (values %h) {
  $m = $_ if $_ > $m;
}
print "$m\n";

my %hash;
my $n = int<>;
my $max = 0;
$hash{<>}++ for(1..$n);
for(values %hash) {
    $max = $_ if ($_ > $max);
}
print $max;

#!/usr/bin/perl
# your code goes here
use v5.10;

@c = (0) x 1440;
chomp($n = <>);
while (<>) {
	chomp;
	($h, $m) = split / /;
	++$c[$h*60+$m];
}
$ans = 0;
$ans=$ans>$_ ? $ans:$_ foreach (@c);
say $ans;

#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(max min);

chomp(my $n = <STDIN>);
my %cnt;
for (my $i = 0; $i < $n; $i++) {
    chomp(my $customer = <STDIN>);
    if (exists($cnt{$customer})) {
        $cnt{$customer} += 1;
    } else {
        $cnt{$customer} = 1;
    }
}

print max values %cnt;

#!usr/bin/perl
#use warnings;
#use strict;
#use autodie;
#use diagnostics;
use utf8;
use 5.010;
use 5.012;
use 5.014;
my($line,$n,$max,$count,$prev,$ans);
$count=0;
$max=1;
$ans=1;
chomp($n=<STDIN>);
while($count ne $n)
{
    chomp($line=<STDIN>);
    if($count eq 0)
    {
        $prev=$line;
        $count++;
        next;
    }
    $count++;
    if($prev eq $line)
    {
        $ans++;
    }
    else
    {
        if($max<$ans)
        {
            $max=$ans;
        }
        $ans=1;
    }
    $prev=$line;
}
if($max<$ans){$max=$ans;}
say $max;

#!/usr/bin/perl -w
use strict;
use warnings;
use List::Util qw(max);

my $n = int <STDIN>;
my %hash;
for (1 .. $n) {
    my ($h, $m) = map int, split /\D/, <STDIN>;
    $m += $h*60;
    if ($hash{$m}) {
	$hash{$m}++;
    } else {
	$hash{$m} = 1;
    }
}
print max values %hash;

my $num = <>;
chomp $num;
my %count;
for (1..$num) {
    my $time = <>;
    chomp $time;
    $count{$time}++;
}
my @temp = sort {$count{$b}<=>$count{$a}} keys %count;
my $time = shift @temp;
print $count{$time};

my $n = int<>;
my @temp;
my @arr;
for (1..$n) {
    @temp = split / /, <>;
    push @arr, $temp[0] * 100 + $temp[1];
}
@arr = sort @arr;
my ($max, $ans) = (0, 0);
for (1..$n - 1) {
    if (int$arr[$_] == int$arr[$_ - 1]) {
        $ans++;
    }
    else {
        $max = $ans if ($ans > $max);
        $ans = 0;
    }
}
print $max + 1;

#!/usr/bin/perl -w

use strict;

my $n = <>;
my ($ch, $cm) = (0, 0);
my $mc = 0;
my $cash = 1;
for (1..$n) {
    my ($h, $m) = split ' ', <>;
    if ($h == $ch && $m == $cm) {
        $cash++;
    } else {
        $cash = 1;
    }
    $ch = $h;
    $cm = $m;
    $mc = $cash > $mc ? $cash : $mc;
}

print $mc, "\n";

#!usr/bin/perl
#use warnings;
#use strict;
#use autodie;
#use diagnostics;
use utf8;
use 5.010;
use 5.012;
use 5.014;
my($line,$n,$max,$count,$prev,$ans);
$count=0;
$max=1;
$ans=1;
chomp($n=<STDIN>);
while($count ne $n)
{
    chomp($line=<STDIN>);
    if($count eq 0)
    {
        $prev=$line;
        $count++;
        next;
    }
    $count++;
    if($prev eq $line)
    {
        $ans++;
    }
    else
    {
        if($max<$ans)
        {
            $max=$ans;
        }
        $ans=1;
    }
    $prev=$line;
}
say $max;


chomp (($_, $b) = <>);
for $j (1 .. length){
	$e .= chop $b ne ($a = chop) ?
		(++ $i % 2 ? $a : 1 - $a)
	:
		0
	}
print $i % 2 ? 'impossible' : scalar reverse $e

#!/usr/bin/perl
use v5.10;

chomp($a = <>);
chomp($b = <>);
$len = length $a;
@a = split //, $a;
@b = split //, $b;
$c = 0;
$a[$_] ne $b[$_] and ++$c foreach (0 .. $len-1);
$c%2>0 and say "impossible" and exit;
for ($i=0,$j=0,$c>>=1; $i<$len; ++$i) {
	if ($a[$i] eq $b[$i]) {
		push @ans, $a[$i];
	} else {
		$j < $c and push @ans, $a[$i] or push @ans, $b[$i];
		++$j;
	}
}
say join '', @ans;

#!/usr/bin/perl
use v5.10;

chomp($a = <>);
chomp($b = <>);
$len = length $a;
@a = split //, $a;
@b = split //, $b;
$c = 0;
$a[$_] ne $b[$_] and ++$c foreach (0 .. $len-1);
$c%2>0 and say "impossible" and exit;
for ($i=0,$j=0; $i<$len; ++$i) {
	if ($a[$_] eq $b[$_]) {
		push @ans, $a[$_];
	} else {
		$j < $c and push @ans, $a[$_] or push @ans, $b[$_];
		++$j;
	}
}
say join '', @ans;

chomp (($_, $b) = <>);
for $j (1 .. length){
	$e .= chop $b ne (chop) ?
		++ $i % 2
	:
		0
	}
print $i % 2 ? 'impossible' : scalar reverse $e

chomp (($_, $b) = <>);
for $j (1 .. length){
	$e .= chop $b ne (chop) ?
		++ $i % 2
	:
		0
	}
print $i % 2 ? 'Impossible' : scalar reverse $e


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	$_ = <>, chomp;

	my %h;

	/
		.
		(?{ $h{ $& } ++ })
		(*F)
		/x;

	my @ans;

	while( not grep !$_, @h{ split //, 'one' } ){
		push @ans, 1;
		map { $_ -- } @h{ split //, 'one' };
		}

	while( not grep !$_, @h{ split //, 'zero' } ){
		push @ans, 0;
		map { $_ -- } @h{ split //, 'zero' };
		}

	print join ' ', @ans;
	}

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

# essential
my @tokens = ();

sub read_line {
    chomp (my $line = <STDIN>);
    return $line;
}

sub read_token {
    @tokens = split q{ }, read_line() if @tokens == 0;
    return shift @tokens;
}

sub min {
    my @numbers = @_;
    my $min = shift @numbers;
    for ( @numbers ) {
        $min = $min<$_ ? $min : $_;
    }
    return $min;
}

sub max {
    my @numbers = @_;
    my $max = shift @numbers;
    for ( @numbers ) {
        $max = $max > $_ ? $max : $_;
    }
    return $max;
}

sub sum {
    my @numbers = @_;
    my $sum = 0;
    for (@numbers) {
        $sum += $_;
    }
    return $sum;
}

sub remainder {
    my ($dividend, $divisor) = @_;
}

# solve

my $length = read_token;
my $input = read_line;

my @chars = split q{}, $input;

my @bins = ();

for (@chars) {
    push @bins, 0 if $_ eq 'z';
    push @bins, 1 if $_ eq 'n';
}

@bins = reverse sort @bins;

say "@bins";


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	my( $n, $A, $B, $C, $T ) = split;

	@_ = split ' ', <>;

	my $sum = 0;

	for( @_ ){
		if( $B > $C ){
			$sum += $A;
			}
		else{
			$sum += $A + ( $T - $_ ) * ( $C - $B );
			}
		}

	print $sum;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;
	my $n = $_;

	my %h;
	my %g;

	for my $i ( 1 .. $n - 1 ){
		my( $u, $v ) = split ' ', <>;

		$g{ $u } ++;
		$g{ $v } ++;
		$h{ $u }{ $v } = $i;
		$h{ $v }{ $u } = $i;
		}

	$_ = join '', sort { $a <=> $b } values %g;

	if( not m/^112*$/ ){
		print -1;
		next;
		}

	my $first;

	for my $i ( 1 .. $n ){
		if( $g{ $i } == 1 ){
			$first = $i;
			last;
			}
		}

	my $second;

	my @seq;

	for my $i ( 1 .. $n - 1 ){
		( $second ) = sort keys %{ $h{ $first } };
		push @seq, [ $h{ $first }{ $second }, $i % 2 ];
		exists $h{ $second }{ $first } and delete $h{ $second }{ $first };
		$first = $second;
		}

	@seq = map $_->[ 1 ], sort { $a->[ 0 ] <=> $b->[ 0 ] } @seq;

	print "@seq" =~ y/10/52/r;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;
	my $n = $_;

	my %h;
	my %g;

	for my $i ( 1 .. $n - 1 ){
		my( $u, $v ) = split ' ', <>;

		$g{ $u } ++;
		$g{ $v } ++;
		$h{ $u }{ $v } = $i;
		$h{ $v }{ $u } = $i;
		}

	$_ = join '', sort { $a <=> $b } values %g;

	if( not m/^112*$/ ){
		print -1;
		next;
		}

	my $first;

	for my $i ( 1 .. $n ){
		if( $g{ $i } == 1 ){
			$first = $i;
			last;
			}
		}

	my $second;

	my @seq;

	for my $i ( 1 .. $n - 1 ){
		( $second ) = keys %{ $h{ $first } };
		push @seq, [ $h{ $first }{ $second }, $i % 2 ];
		exists $h{ $second }{ $first } and delete $h{ $second }{ $first };
		$first = $second;
		}

	@seq = map $_->[ 1 ], sort { $a->[ 0 ] <=> $b->[ 1 ] } @seq;

	print "@seq" =~ y/10/52/r;
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	chomp;

	my $div = int $_ / 2020;

	my $div_plus = 2021 * $div;

	if( $div_plus >= $_ ){
		print "YES";
		}
	else{
		print "NO";
		}
	}


my $max;
my $min;

open(FH, '<', 'input.txt');

for(1..<FH>) {
        $min = 9999999;
        $max = 0;
        <FH>;
        chomp (my $in = <FH>);
        @a = split / /, $in;
        foreach (@a){
                if ($_ > $max) {
                        $max = $_;
                }
                if ($_ < $min) {
                        $min = $_;
                }
        }
        print $max - $min;
        print "\n";
}


# perform dfs to make the connected
# components
sub make_disjoint_sets {

    my ($lst_ref, $visit_ref, $ds_ref, $curr, $id ) = @_;

    if ( exists $visit_ref -> { $curr } ) {
	return;
    }

    $visit_ref -> { $curr } = 1;
    $ds_ref -> { $curr } = $id;

    for my $adjacent ( keys %{ $lst_ref -> { $curr } } ) {
	&make_disjoint_sets ( $lst_ref, $visit_ref,
			     $ds_ref, $adjacent, $id );
    }

    return;
}

# use a hash as a set to count the number
# of unique sets
sub count_disjoint_sets {

    my $ds_ref = $_[0];
    my %count_set = ();

    for my $i (values %{ $ds_ref }) {
	$count_set { $ds_ref -> { $i } } = 1;
    }

    my $val = (scalar (keys %count_set));
    return $val;
}

my $f = <STDIN>;
chomp ( $f );
my ($n, $m) = split m/ /, $f;

my %disjoint_sets = ();
my %lst = ();
my %visit = ();

my $a, $b;
for my $i (1..$m) {
    $f = <STDIN>;
    chomp ( $f );
    ($a, $b) = split m/ /, $f;
    $lst { $a }{ $b } = 1;
    $lst { $b }{ $a } = 1;
}

for my $i (1..$n) {
    &make_disjoint_sets ( \%lst, \%visit, \%disjoint_sets, $i, $i );
}

my $cc = &count_disjoint_sets ( \%disjoint_sets );

my $answer = (2 ** ($n - $cc));

print "$answer\n";


sub maxInd {
    (my $max, my $index) = (0, 0);
    for($i = 0; $i <= $#_; $i++)
    {
        if($max < $_[$i]) {
            $max = $_[$i];
            $index = $i;
        }
    }
    $index;
}

sub minInd {
    (my $min, my $index) = (100, 0);
    for($i = $#_; $i >= 0; $i--)
    {
        if($min > $_[$i]) {
            $min = $_[$i];
            $index = $i;
        }
    }
    $index;
}

<STDIN>;
chomp($s = <STDIN>);
@arr = split(/ /, $s);
$max = &maxInd(@arr);
$min = &minInd(@arr);
$answer = $max + abs($#arr - $min);
print $max - $min > 0 ? --$answer : $answer;

#!/usr/bin/perl -w

use strict;

<>;
my @a = split ' ', <>;

my $imax = 0;
my $imin = 0;
$imax = $a[$_] > $a[$imax] ? $_ : $imax for 1..$#a;
$imin = $a[$_] <= $a[$imin] ? $_ : $imin for 1..$#a;

print $imax > $imin ? ($imax + ($#a - $imin) - 1) : ($imax + ($#a - $imin)), "\n";

chomp($n = <STDIN>);
@soldiers = split /\s+/, <STDIN>;

%pos = { };
$tall = -1;
$small = 99999;

for($s=0;$s < $n; $s++) {
	if($soldiers[$s] > $tall) {
		$tall = $soldiers[$s];
		$pos{'tall'} = $s;
	}
	if($soldiers[$s] <= $small) {
		$small = $soldiers[$s];
		$pos{'small'} = $s;
	}
}

#print "Tallest in pos ".$pos{'tall'}.", smallest in ".$pos{'small'}."\n";

$swaps = $pos{'tall'} + ($n - $pos{'small'} - 1);
if($pos{'tall'} > $pos{'small'}) { $swaps--; }
print "$swaps\n";

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

my $n = <STDIN>;
my @soldiers = split(' ', <STDIN>);
my $min = 100000;
my $min_position = 0;
my $max = -1;
my $max_position = 0;

for (my $i = 0; $i < $n; $i++)
{
    my $soldier = $soldiers[$i];
    if ($soldier > $max)
    {
        $max = $soldier;
        $max_position = $i;
    }
    if ($soldier <= $min)
    {
        $min = $soldier;
        $min_position = $i;
    }
}

my $result = $max_position + ($n - 1 - $min_position);
if ($max_position > $ min_position)
{
    $result--;
}

print $result;

sub maxInd {
    (my $max, my $index) = (0, 0);
    for($i = 0; $i <= $#_; $i++)
    {
        if($max < $_[$i]) {
            $max = $_[$i];
            $index = $i;
        }
    }
    $index;
}

sub minInd {
    (my $min, my $index) = (100, 0);
    for($i = $#_; $i >= 0; $i--)
    {
        if($min > $_[$i]) {
            $min = $_[$i];
            $index = $i;
        }
    }
    $index;
}

chomp($s = <STDIN>);
@arr = split(/ /, $s);
$max = &maxInd(@arr);
$min = &minInd(@arr);
$answer = $max + abs($#arr - $min);
print $max - $min > 0 ? --$answer : $answer;


#!/usr/bin/perl
use v5.10;

chomp($n = <>);
360%(180-<>)==0 and say "YES" or say "NO" foreach (1..$n);

use 5.016;
use strict;
use warnings;

sub is_regular_angle {
  my ($theta) = @_;

  my $outside = 180 - $theta;
  360 % $outside == 0;
}

my $n = <>;
for (1..$n) {
  my $theta = <>;
  say is_regular_angle($theta) ? 'YES' : 'NO';
}

#!usr/bin/perl
#use warnings;
#use strict;
#use autodie;
#use diagnostics;
use utf8;
use 5.010;
use 5.012;
use 5.014;
my($count,$t,$n);
chomp($t=<STDIN>);
$count=0;
while($count != $t)
{
	$count++;
	chomp($n=<STDIN>);
	$n=180-$n;
	$n=360/$n;
	if($n=~/\./)
	{
		say "NO";
	}
	else
	{
		say "YES";
	}
}

my $num = <>;
chomp $num;
for (1..$num) {
    my $angle = <>;
    chomp $angle;
    (360%(180-$angle)) ? print "NO\n" : print "YES\n";
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;
my $debug = 0;

while(<>){
	my( $n, $m ) = split;

	my @A;

	( $_ = <>, chomp ), push @A, [ split // ] for 1 .. $n;

	my $fail = 0;

	for my $i ( 0 .. $n - 1 ){
		for my $j ( 0 .. $m - 1 ){
			next if $A[$i][$j] eq '*';

			my $bombs = 0;

			$i > 0 and $A[$i-1][$j+0] eq '*' and $bombs ++;
			$i > 0 and $j > 0 and $A[$i-1][$j-1] eq '*' and $bombs ++;
			$i > 0 and $j < $m - 1 and $A[$i-1][$j+1] eq '*' and $bombs ++;
			$i < $n - 1 and $A[$i+1][$j+0] eq '*' and $bombs ++;
			$i < $n - 1 and $j > 0 and $A[$i+1][$j-1] eq '*' and $bombs ++;
			$i < $n - 1 and $j < $m - 1 and $A[$i+1][$j+1] eq '*' and $bombs ++;
			$j > 0 and $A[$i+0][$j-1] eq '*' and $bombs ++;
			$j < $m - 1 and $A[$i+0][$j+1] eq '*' and $bombs ++;

			$debug and print $bombs;

			next if $A[$i][$j] eq '.' and not $bombs;

			if( $bombs ne $A[$i][$j] ){ $fail = 1; }
			}
		}

	print $fail ? "NO" : "YES";

	$debug and print '-' x 15;
	}

use warnings;
use strict;
use constant NL => qq/\n/;

my ( $n, $m ) = (<STDIN> =~ m/(\d+)\s(\d+)/);
my @arr = ();
for ( 1 .. $n ) {
    my $line = <STDIN>;
    push @arr, [ split qq//, $line ] }
my $is_valid = 1;

AA: for my $i ( 0 .. ($n-1) ) {
    AB: for my $j ( 0 .. ($m-1) ) {
        if ( $arr [ $i ][ $j ] eq '.' ) {
            AC: for my $one ( ($i-1) .. ($i+1) ) {
                AD: for my $two ( ($j-1) .. ($j+1) ) {
                    if ( $one eq $i and $two eq $j ) { next AD }
                    if ( $one >= 0 and $two >= 0 and $one < $n and $two < $m and
                         ($arr [ $one ][ $two ] eq '*') ) {
                        $is_valid = 0;
                        last AA }}}}
        elsif ( $arr [ $i ][ $j ] ne '*' ) {
            my $sum = 0;
            AE: for my $one ( ($i-1) .. ($i+1) ) {
                AF: for my $two ( ($j-1) .. ($j+1) ) {
                    if ( $one eq $i and $two eq $j ) { next AF }
                    if ( $one >= 0 and $two >= 0 and
                         $one < $n and $two < $m and
                         ( $arr [ $one ][ $two ] eq '*') ) { $sum += 1 } }}
            if ( $sum != $arr [ $i ][ $j ] ) {
                $is_valid = 0;
                last AA }}
    }
}

print qq/YES\n/ if $is_valid;
print qq/NO\n/ if not $is_valid;


use strict;
use warnings;

use Data::Dumper;
$,=" ";
my ($n,$c)=split / /,<>;
chomp($n,$c);
my $sum=1;
my @t=split  / /,<>;
chomp(@t);
my $a=shift @t;
for(@t)
{
if($_-$a<=$c)
{
$sum++ ;
}
else
{
  $sum=1;
}
$a=$_;
}

print $sum . "\n";

use 5.016;
use strict;
use warnings;

my ($n, $c) = split ' ', <>;
my @times = split ' ', <>;
my $last = 0;
my $count = 0;

for my $time (@times) {
  if ($time - $last > $c) {
    $count = 1;
  } else {
    $count++;
  }

  $last = $time;
}

say $count;


# open STDIN,"<","a.in" or die $!;
my $a1 = ReadLine();
my $a2 = ReadLine();
$a1 =~ s/^0+//;
$a2 =~ s/^0+//;

# print "$a1 $a2";
my ($len1,$len2) = (length($a1),length($a2));
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

print "\n";

sub ReadLine {
    my $line = <STDIN>;
    chop($line);
    my $lll = length($line);
    while(not $lll) {
        $line = <STDIN>;
        chop($line);
        $lll = length($line);
    }
    return $line;
}

#open STDIN,"<","a.in" or die $!;
my $a1 = ReadLine();
my $a2 = ReadLine();
$a1 =~ s/^0+//; # 去前导零
$a2 =~ s/^0+//;

# print "$a1 $a2";
my ($len1,$len2) = (length($a1),length($a2));
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

print "\n";

sub ReadLine { # 读一行非空的字符串
    chop(my $line = <STDIN>);
    while(not length($line)) {
        chop($line = <STDIN>);
    }
    return $line;
}

#open STDIN,"<","a.in" or die $!;
my $a1 = ReadLine();
my $a2 = ReadLine();
$a1 =~ s/^0+//;
$a2 =~ s/^0+//;

# print "$a1 $a2";
my ($len1,$len2) = (length($a1),length($a2));
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

print "\n";

sub ReadLine {
    my $line = <STDIN>;
    chop($line);
    while(not length($line)) {
        chop($line = <STDIN>);
    }
    return $line;
}

$ch1=<>;
chomp $ch1;
$ch2=<>;
chomp$ch2;

$ch1=~m/^(0*)./;

$ll1=length$1;
$ch2=~m/^(0*)./;

$ll2=length$1;
$l1=length$ch1;
$l2=length$ch2;

if($l1-$ll1>$l2-$ll2){
print ">";
}
elsif($l1-$ll1<$l2-$ll2){
print "<";
}

elsif(substr($ch1,$ll1) gt substr($ch2,$ll2)){
print ">";
}
elsif(substr($ch1,$ll1) lt substr($ch2,$ll2)){
print "<";
}
else{
print "=";
}

($A, $B) = map { chomp; s/^0+//r } <>;

$W = 0;

print qw(= > <)[ length $A <=> length $B || do {
			for (1 .. length $A) { $W = chop $A <=> chop $B || $W }
			$W
		}
	]

my $a1 = <STDIN>;
my $a2 = <STDIN>;
$a1 =~ s/0+//;
$a2 =~ s/0+//;
my ($len1,$len2) = (length($a1),length($a2));
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

#open STDIN,"<","a.in" or die $!;
my $a1 = <STDIN>;
my $a2 = <STDIN>;
$a1 =~ s/^0+//;
$a2 =~ s/^0+//;

my ($len1,$len2) = (length($a1),length($a2));
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

my $a1 = <STDIN>;
my $a2 = <STDIN>;
if($a1 == $a2) {
    print "=";
}
elsif($a1 > $a2) {
    print ">";
}
else {
    print "<";
}

#open STDIN,"<","a.in" or die $!;
my $a1 = <STDIN>;
my $a2 = <STDIN>;
$a1 =~ s/^0+//;
$a2 =~ s/^0+//;

my ($len1,$len2) = (length($a1),length($a2));
print "$len1 $len2" if ($a2 eq "8");
if($len1 eq $len2) {
    if($a1 eq $a2) {print "=";}
    elsif($a1 ge $a2) {print ">";}
    else {print "<"};
}
elsif($len1 ge $len2) {print ">";}
else {print "<";}

$ch1=<>;
chomp $ch1;
$ch2=<>;
chomp$ch2;
$num1=int($ch1);
$num2=int($ch2);
if($num2==$num1){
print "=";
}
elsif ($num1>$num2){
print">";
}
else{
print "<";
}


sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
#	my $p = 1;
#	print "col = $col\n";
	while($col > 26) {
		my $tmp = int($col / 26);
		my $v = $col - $tmp * 26;
#		print "col = $col, p = $p, tmp = $tmp, v = $v\n";
		if($v==0) { $v = 26; $col -= 26; }
		$ret .= chr(64+$v);
		$col = int($col/26);
#		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col > 26) {
            my $r = $col % 26;
            $r = 26 if !$r;
            push @col, $r;
            $col = int (($col-$r)/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

#!/usr/local/bin/perl
$n = <>;
for ( 1 .. $n ) {
    $line = <>;

    if ( $line =~ /(\D+)(\d+)(\D+)(\d+)/ ) {
        print makeNormal($2,$4)."\n";

    }
    elsif($line =~ /(\D+)(\d+)/ ){
        print makeRC($1 , $2)."\n";
    }

}
    sub makeNormal {
        use integer;
        my $row = $_[0];
        my $col = $_[1];
        my @alph = (A..Z);

        $result = $row;
        do{
            my $r, $letter;
            $col -= 1;
            $r = $col % 26;
            $col = $col / 26;
            $result = @alph[$r].$result;
        } while ($col);
        return $result;
    }

    sub makeRC {
        use integer;
        my $row = $_[1];
        my $col = $_[0];
        my $resCol = 0;
        my $n = 1;
        my $A = ord("A");
        foreach $ch (reverse split (// , $col)){
            $resCol+= (ord($ch) - $A +1) * $n;
            $n *= 26;
        }
        return "R".$row."C".$resCol;

    }

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $tmp = $cur % 26;
        $tmp = 26 if ($tmp==0);
        my $c = chr(ord("A") + $tmp - 1);
        $result = $result.$c;
        $cur = ($cur - $tmp) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t%26};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 0) {
            $new_char = ($col % 26 == 0 ? $num2char{26} : $num2char{$col % 26}) . $new_char;
            if ($col % 26 == 0) { $col--; }
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

use strict;
use warnings;

use 5.012;

my $num_inputs = <>;
my @inputs;

for ( 1 .. $num_inputs ) {
  my $input = <>;
  chomp $input;
  if ( $input =~ /\AR(\d+)C(\d+)\z/ ) {
    printf "%s%s\n", row_num_to_letter($2), $1;
  }
  else {
    $input =~ /\A([A-Z]+)(\d+)\z/;
    printf "R%sC%s\n", $2, row_letter_to_num( $1 );
  }
}

sub row_num_to_letter {
  my ( $num ) = @_;
  my $str = '';
  while ( $num > 0 ) {
    if ( my $left = $num % 26 ) {
      $str = chr( $left + 64 ) . $str;
      $num = int( $num / 26 );
    } else {
      $str = 'Z' . $str;
      $num = int( $num / 26 ) - 1;
    }
  }
  return $str;
}

sub row_letter_to_num {
  my ( @letters ) = split //,  $_[0];
  my $num = 0;
  my $scale = 0;
  while ( @letters ) {
    my $letter = pop(@letters);
    my $nvalue = ord($letter) - 64;
    $num = $num + ( $nvalue * ( 26 ** $scale ) );
    $scale ++;
  }
  return $num;
}

use strict;
use warnings;

my $totalNum =  <STDIN>;

my @inputs;
for(my $i = 0; $i < $totalNum; $i++){
    my $input = <STDIN>;
    push @inputs, $input;
}

foreach my $input (@inputs){
#    print $input . "\n";
    if ( $input =~ /^R([0-9]+)C([0-9]+)$/){
        print convert26($2) . "$1" . "\n";
    }
    if ($input =~ /^([A-Z]+)(\d+)$/ ){
        print "R$2" . "C" . iconvert26($1) . "\n";
    }
}

#
#foreach my $i (1..250){
#    print convert26($i), " ";
#}
#
#print "\n";
#

#foreach my $i ('AA'..'AZ'){
#    print iconvert26($i), "  ";
#}

#===================================================================
sub convert26
{
	my ($input) = @_;
	my $base = 26;
	my @elements = ( 'A'..'Z');
	my @ret=();
	do{
	    unshift @ret, $elements[($input)%$base -1];
	    $input = int(($input-1) /$base);
	}while($input);
	return join('', @ret);
}

sub iconvert26
{
    my ($input) = @_;
    my $base = 26;
    my @elements = ('', 'A'..'Z');
    my @inputs = reverse (split("", $input));
    my $ret = 0;
    my $pos = 0;
    foreach my $in (@inputs){
        my $index = 0;
        foreach my $elem (@elements){

            if($elem eq $in){
                last;
            }
            $index ++;
        }
        $ret += $index  * $base ** $pos;
        $index = 0;
        $pos++;
    }
    return $ret;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        while ($c > 0) {
            $res = chr(ord('A') + ($c + 25)%26).$res;
            if ($c % 26) {
                $c = int($c/26);
            } else {
                $c = $c/26 - 1;
            }
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

use strict;
use warnings;

use 5.012;

my $num_inputs = <>;
my @inputs;

for ( 1 .. $num_inputs ) {
  my $input = <>;
  chomp $input;
  if ( $input =~ /\AR(\d+)C(\d+)\z/ ) {
    printf "%s%s\n", row_num_to_letter($2), $1;
  }
  else {
    $input =~ /\A([A-Z]+)(\d+)\z/;
    printf "R%sC%s\n", $2, row_letter_to_num( $1 );
  }
}

sub row_num_to_letter {
  my ( $num ) = @_;
  my $str = '';
  while ( $num > 26 ) {
    my $left = $num % 26;
    $str = chr( $left + 64 ) . $str;
    $num = int( $num / 26 );
  }
  return chr( $num + 64 ) . $str;
}
sub row_letter_to_num {
  my ( @letters ) = split //,  $_[0];
  my $num = 0;
  my $scale = 0;
  while ( @letters ) {
    my $letter = pop(@letters);
    my $nvalue = ord($letter) - 64;
    $num = $num + ( $nvalue * ( 26 ** $scale ) );
    $scale ++;
  }
  return $num;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        while ($c > 0) {
            $res = chr(ord('A') - 1 + $c%26).$res;
            $c = int($c/26);
#            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        foreach (split "", $1) {
#            print "$_\n";
            $c *= 26;
            $c += ord($_) - ord('A') + 1;
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        foreach (split "", $1) {
            print "$_\n";
            $c *= 26;
            $c += ord($_) - ord('A') + 1;
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	while($col > 26) {
		$ret .= chr(64+($col % 26));
		$col /= 26;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $p = length($col)-1;
	my $c = 0;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
			$col -= 26**$p;
		} else {
			my $tmp = int($col / 26);
#		$tmp = 1 if($tmp == 0);
			my $v = $col - $tmp * 26;
#			print "Got $v, it turns into ".chr(64+$v)."\n";
			$ret .= chr(64+$v);
		}
		$col = int($col/26);
		$p++;
	}

	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	while($col > 26) {
		$ret .= chr(64+($col % 26));
		$col /= 26;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	for(my $p=$l;$p>=0;$p--) {
		my $ltr = substr($col,($p-$l), 1);
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
			$col /= 26;
		} else {
			my $tmp = int($col / 26);
			my $v = $col - $tmp * 26;
			$ret .= chr(64+$v);
			$col /= 26;
		}
		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
$col -= 26**$p;
			$col /= 26;
		} else {
			my $tmp = int($col / 26);
			my $v = $col - $tmp * 26;
			$ret .= chr(64+$v);
			$col /= 26;
		}
		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

#!/bin/perl -w
use strict;
use warnings;

sub ntos {
# Slow, but should be OK
    my $n = shift;
    my $s = 'A';
    for (1 .. $n - 1) { $s++; }
    return $s;
}

sub ston {
    my $s = shift;
    my %hash;
    @hash{('A'..'Z')} = (1 .. 26);
    my $n = 0;
    for (split //, $s) {
	$n *= 26;
	$n += $hash{$_};
    }
    return $n;
}

sub main {
    my $n = int <>;
    for (1 .. $n) {
	my $s = <>;
	if ($s =~ /^R([\d]*)C([\d]*)$/) {
	    print ntos($2) . "$1\n";
	} elsif ($s =~ /^([\D]*)([\d]*)$/) {
	    print "R$2C" . (ston $1) . "\n";
	} else {
	    exit(-1);
	}
    }
}

main();

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>=26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return (($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26)),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t==1){return "A";}
    elsif($t>26){return ntl(int($t/26),$ln).$$ln{$t%26};}
    else{return $$ln{$t-1};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return (($t%26)?ntl(int($t/26-1),$ln):ntl(int($t/26)),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return ntl(int($t/26),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        #print "Row-column to column-row\n";
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 0) {
            $new_char = $num2char{$col % 26} . $new_char;
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        #print "Column-row to row-column $1, $2\n";
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        #print "Row-column to column-row\n";
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 1) {
            $new_char = ($col % 26 == 0 ? $num2char{26} : $num2char{$col % 26}) . $new_char;
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        #print "Column-row to row-column $1, $2\n";
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

#!/usr/local/bin/perl
$n = <>;
for ( 1 .. $n ) {
    $line = <>;

    if ( $line =~ /(\D+)(\d+)(\D+)(\d+)/ ) {
        print makeNormal($2,$4);

    }
    elsif($line =~ /(\D+)(\d+)/ ){
        print makeRC($1 , $2);
    }

}
    sub makeNormal {
        use integer;
        my $row = $_[0];
        my $col = $_[1];
        my @alph = (A..Z);

        $result = $row;
        do{
            my $r, $letter;
            $col -= 1;
            $r = $col % 26;
            $col = $col / 26;
            $result = @alph[$r].$result;
        } while ($col);
        return $result;
    }

    sub makeRC {
        use integer;
        my $row = $_[1];
        my $col = $_[0];
        my $resCol = 0;
        my $n = 1;
        my $A = ord("A");
        foreach $ch (reverse split (// , $col)){
            $resCol+= (ord($ch) - $A +1) * $n;
            $n *= 26;
        }
        return "R".$row."C".$resCol;

    }

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col >= 26) {
            push @col, $col % 26;
            $col = int ($col/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col >= 26) {
            push @col, $col % 26;
            $col = int (($col-1)/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row\n";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".$row."C".convertFromSymbols($col)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + ($cur - 1) % 26);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".$row."C".convertFromSymbols($col);
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".convertFromSymbols($col)."C$row";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	my $length = length;

	$debug and print '-' x 15;
	$debug and print;

	my @ans;

	my $len = 0;

	s/^a*b+(?=a)// and do {
		$len += length $&;
		push @ans, $len;
		};

	while( /a/ ){
		s/a+// and do {
			$len += length $&;
			push @ans, $len;
			};

		s/b+(?=a)// and do {
			$len += length $&;
			push @ans, $len;
			};
		}

	$debug and print "@ans";

	my @ANS = ( 0 ) x $length;

	for( @ans ){
		$ANS[ $_ - 1 ] = 1;
		}

	print "@ANS";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	chomp;

	@_ = ();

	my $q = 0;

	while( 1 < length ){
		my $ch = chop;
		my $front = substr $_, 0, 1;

		if( 0 ){ ; }
		elsif( $front eq 'b' and $ch eq 'b' ){
			push @_, 0;
			}
		elsif( $front eq 'a' and $ch eq 'b' ){
			if( $q ){
				push @_, 1;
				$_ = reverse( $_ . $ch );
				chop;
				$q = 0;
				}
			else{
				push @_, 0;
				}
			}
		elsif( $front eq 'b' and $ch eq 'a' ){
			push @_, 1;
			$_ = reverse( $_ . $ch );
			chop;
			}
		elsif( $front eq 'a' and $ch eq 'a' ){
			push @_, $q ? 0 : '?';
			$q ||= 1;
			}
		}

	my $last = $_;

	push @_, 0;
	@_ = reverse @_;
#%	print "@_";

	my $one = 0;

	for( @_ ){
		/\?/ and $one and do {
			$_ = 1;
			};
		/\?/ and $one = 1;
		}

	for( @_ ){
		/\?/ and do {
			$_ = $last eq 'b' ? 1 : 0;
			last;
			};
		}

	print "@_";
	}


#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	$debug and print '-' x 15;

	chomp;

	if( 1 == length ){
		print for "YES", join '', 'a' .. 'z';
		next;
		}

	my %h;

	/
		(.)
		(?=(.))
		(?{ $h{ join '', sort $1, $2 } ++ })
		(*FAIL)
		/x;

	$debug and print ":$_ --> [$h{ $_ }]" for sort keys %h;

	@_ = map { [ split '' ] } sort keys %h;

	my $alphabet = join '', @{ shift @_ };

	my %alphabet;

	$alphabet{ $_ } = 0 for 'a' .. 'z';

	map { $alphabet{ $_ } ++ } split '', $alphabet;

	my $j = 26 ** 1 + 2;

	while( @_ ){
		$j -- < 0 and last;

		my $try = shift @_;

		if( 1 != $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			push @_, $try;
			next;
			}

		my $fail = 0;

		if( 0 ){ ; }
		elsif( $alphabet =~ /^$try->[ 0 ]/ ){
			$alphabet = $try->[ 1 ] . $alphabet;
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /^$try->[ 1 ]/ ){
			$alphabet = $try->[ 0 ] . $alphabet;
			$alphabet{ $try->[ 0 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 0 ]$/ ){
			$alphabet .= $try->[ 1 ];
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 1 ]$/ ){
			$alphabet .= $try->[ 0 ];
			$alphabet{ $try->[ 0 ] } ++;
			}
		else{
			$fail = 1;
			}

		if( $fail ){
			push @_, $try;
			}
		}

	$debug and print "alphabet:[$alphabet]|\@_:[@_]|j:[$j]";

	if( $j == -2 ){
		print "NO";
		}
	else{
		print for "YES", $alphabet . ( join '', 'a' .. 'z' ) =~ s/[$alphabet]//gr;
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	$debug and print '-' x 15;

	chomp;

	if( 1 == length ){
		print for "YES", join '', 'a' .. 'z';
		next;
		}

	my %h;

	/
		(.)
		(?=(.))
		(?{ $h{ join '', sort $1, $2 } ++ })
		(*FAIL)
		/x;

	$debug and print ":$_ --> [$h{ $_ }]" for sort keys %h;

	@_ = map { [ split '' ] } sort keys %h;

	my $alphabet = join '', @{ shift @_ };

	my %alphabet;

	$alphabet{ $_ } = 0 for 'a' .. 'z';

	map { $alphabet{ $_ } ++ } split '', $alphabet;

	my $j = 26 ** 1 + 2;

	while( @_ ){
		$j -- < 0 and last;

		my $try = shift @_;

		if( 2 == $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			$j = -2;
			last;
			}

		if( 0 == $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			push @_, $try;
			next;
			}

		my $fail = 0;

		if( 0 ){ ; }
		elsif( $alphabet =~ /^$try->[ 0 ]/ ){
			$alphabet = $try->[ 1 ] . $alphabet;
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /^$try->[ 1 ]/ ){
			$alphabet = $try->[ 0 ] . $alphabet;
			$alphabet{ $try->[ 0 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 0 ]$/ ){
			$alphabet .= $try->[ 1 ];
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 1 ]$/ ){
			$alphabet .= $try->[ 0 ];
			$alphabet{ $try->[ 0 ] } ++;
			}
		else{
			$fail = 1;
			}

		if( $fail ){
			push @_, $try;
			}
		}

	$debug and print "alphabet:[$alphabet]|\@_:[@_]|j:[$j]";

	if( $j == -2 ){
		print "NO";
		}
	else{
		print for "YES", $alphabet . ( join '', 'a' .. 'z' ) =~ s/[$alphabet]//gr;
		}
	}


#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

$filler = "~";
push @letters, $filler if @letters[$#letters] eq "," or @letters[$#letters] eq ";";
@letters = ($filler, @letters) if @letters[0] eq "," or @letters[0] eq ";";

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$a = '-' if $a eq "";
$b = '-' if $b eq "";

$b =~ s/$filler//g;

print $a eq "-" ? '-' : qq("$a");
print $b eq "-" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

$end_filler = "~";
push @letters, $end_filler if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : $b =~ m/(.*)$end_filler$/ ? qq("$1") : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

print $a;
print $b;

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

$a eq '-' ? print '-' : print "\"$a\"";
$b eq '-' ? print '-' : print "\"$b\"";

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : $b eq "," ? qq("") : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

print "\"$a\"";
print "\"$b\"";

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");