CANDLE problem in Perl

Hello Everyone.I was trying CANDLE problem in Perl.Here is my code.

#!/usr/bin/perl
$t = <STDIN>;
for($c=1;$c<=$t;$c++)
{
$p = 1;
for($i=0;$i<10;$i++)
{
	$arr[$i] = <STDIN>;
}
print "\n";
$l = $arr[1];
for($i=1;$i<10;$i++)
{
	if($arr[$i]<$l)
	{
		$l = $arr[$i];
		$p = $i;
	}
}
if($arr[0]!=0)
{
	if($l!=0)
	{
		if($arr[0]<$l)
		{
			print "1";
			for($i=0;$i<=$arr[0];$i++)
			{
				print "0";
			}
			print "\n";
		}
		else
		{
			for($i=0;$i<=$l;$i++)
			{
				print "${p}";
			}
			print "\n";
		}
	}
	elsif($l==0)
	{
		print "$p\n";
	}
}
elsif($arr[0]==0)
{
	if($l!=0)
	{
		print "10\n";
	}
	else
	{
		print "${p}\n";
	}
}

}

It is showing wrong answer.

Please help.