Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

<?php
$n = (int)readline();
for($i = 0; $i < $n; $i++) {
    $input = readline();
    $len = strlen($input);
    if($len <= 10)
        $output[] = $input . "\n";
    else
        $output[] = $input[0] . ($len-2) . $input[$len - 1] . "\n";
}
foreach ($output as $o)
    echo $o;

<?php

$is_first = true;
while ($row = fgets(STDIN)) {
    if ($is_first === true) {
        $is_first = false;
        continue;
    }
    $length = strlen($row) - 2;
    if ($length > 10) {
        echo $row[0] . ($length - 2) . $row[$length - 1] . "\n";
    } else {
        echo $row . "\n";
    }
}

<?php

//fscanf(STDIN, "%d\n", $number); // reads number from STDIN
$number = trim(fgets(STDIN)); // reads one line from STDIN
$i=0;

while($i<$number && $line= trim(fgets(STDIN))){

    $str = $line;
    $ln = strlen($str) ;

    if($ln>10){
        fwrite(STDOUT, $str[0].($ln-2).$str[$ln-1]."\n");
    }else{
        fwrite(STDOUT, $str."\n");
    }
}

<?php //php 7.2.24
$l = fgets(STDIN);
while(fscanf(STDIN, "%s", $i)){
    if(strlen($i) > 10){ echo $i[0].(strlen($i)-2).$i[strlen($i)-1]."\n"; }
    else echo $i."\n";
}
?>

<?php

$howMany = readline("How many words?:");
$howManyToInt = intval($howMany);
$wordsArr = [];
for($i = 1;$i < $howManyToInt+1; $i++){

	$word = readline("Enter word ".$i." :");
	array_push($wordsArr, $word);
}

foreach($wordsArr as $word){

	$split = str_split($word);
	if(sizeof($split) > 10){

		for($i = 0;$i < sizeof($split); $i++){

			$last = sizeof($split) -1;
			$comp = sizeof($split) -2;

			echo $split[0].$comp.$split[$last]."\n";
			break;
		}

	}else{
		echo $word."\n";
	}
}

<?php

function go($word)
{
    $length = strlen($word);
    $result = substr($word,0,1);
    $result .= $length-2;
    $result .= substr($word,-1,1);
    return $result ;
}

$line_number = 0;
while($f = fgets(STDIN)){
    $line_number++;
    if($line_number == 1)
        $count = trim($f);
    else
    {
        $word=trim($f);
        if(strlen($word)>10) {
            $s=go($word);
            echo $s.PHP_EOL;
        }
        else
            echo $word.PHP_EOL;
    }
}

<?php
$lines = (int)fgets(STDIN);
if($lines >= 1 && $lines <= 100)
{
    $words = [];
    for($i = 0;$i < $lines; $i++)
        $words[$i] = fgets(STDIN);
    foreach($words as $word)
    {
        if(strlen($word) > 12)
            echo $word[0]."".(strlen($word) - 4) ."".$word[-3]."\n";
        else
            echo $word;

    }
}
else
{
    echo "Not valid input\n";
}

?>

<?php
    fscanf(STDIN,'%d',$no_word);
    for ($i=0; $i<$no_word; $i++) {
        fscanf(STDIN,'%s',$word);
        $length = strlen($word);
        if (strlen($word) <= 10) {
            echo $word . "\n";
        } else {
            echo substr($word,0,1) . ($length-2) . substr($word,$length-1,1) . "\n";
        }
    }
?>

<?php
while ($t=fgets(STDIN))
{
    $textmassiv[]=$t;
}
for ($i =0;$i<$textmassiv[0];$i++)
{
    if (strlen(trim($textmassiv[$i+1]))>10)
    {
        echo substr($textmassiv[$i+1],0,1);
        echo strlen(trim($textmassiv[$i+1]))-2;
        echo substr(trim($textmassiv[$i+1]),-1,1)."\n";
    }
    else
    {
        echo trim($textmassiv[$i+1])."\n";
    }
}
?>

<?php
class LongWords {
    public function getResult($str) {
        $lowercase = $str;
        $strlen = strlen($lowercase);
        if($strlen > 10) {
            $eachstr = str_split($lowercase);
            $result = $strlen - 2;
            return $eachstr[0].$result.$eachstr[$strlen-1];
        } else{
            return $lowercase;
        }
    }
}
$obj = new LongWords();

function getinput() {
    return trim(fgets(STDIN));
}

$t = (int)getinput();
// print gettype($t);
while($t--) {
    print $obj->getResult(getinput())."\n";
}

<?php
$n = (int)fgets(STDIN);

$words = array();

for ($i = 1; $i <= $n; $i++) {
    $words[$i] = trim(fgets(STDIN));
}

for ($i = 1; $i <= $n; $i++) {
    $word = $words[$i];
    if (strlen($word) > 10) {
        echo substr($word, 0, 1) . (strlen($word) - 2) . substr($word, -1, 1);
    } else {
        echo $word;
    }
    echo "\n";
}

<?php
  // $input = file_get_contents('./input.txt', 'r');
  $input = file_get_contents('php://stdin', 'r');
  $rows = explode("\n", trim($input));
  $N = (int)$rows[0];
  $arr = array();

  for($i = 0 ; $i < $N; $i++) {
    $row = trim($rows[$i + 1]);
    if (strlen($row) <= 10) {
      $arr[] = $row;
    } else {
      $firstcher =  substr($row, 0, 1);
      $lastcher = substr($row, strlen($row)-1, 1);
      $row = $firstcher . (strlen($row)-2) . $lastcher;
      $arr[] = $row;
    }
  }
  echo implode("\n", $arr);
?>

<?php

    $n = trim(fgets(STDIN));
    $arr = [];
    for($i = 0; $i < $n; $i++) {
        $w = trim(fgets(STDIN));
        if (strlen($w) > 10) {
            $length = strlen($w);
            $e = substr($w, -1);
            $a = $w[0] . (string)($length - 2) . $e;
            echo($a . PHP_EOL);
        } else {
            //$arr[$i] = $w;
            echo($w . PHP_EOL);
        }
    }

<?php

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

$number = (int)trim(fgets($handle));

while($number >= 0){

  $word = trim(fgets($handle));

  $length = strlen($word);

  if($length > 10){

    echo $word[0]. ($length - 2) . $word[$length - 1]."\r";

  }else{

    echo $word."\r";

  }

  $number--;
}

fclose($handle);

<?php
$j = fgets(STDIN);
while($s = fgets(STDIN)) $arr[] = $s;
foreach($arr as $s) {
    $s = trim($s);
    $str_len = strlen($s);
    if($str_len>10) {
        echo $s{0}.($str_len-2).$s{$str_len-1}."\n";
    } else echo $s."\n";
}
?>

<?php

// 85038859 	Jun/25/2020 17:04UTC+1 	celyes 	A - Way Too Long Words 	PHP 	Accepted 	31 ms 	5900 KB

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

$number = (int)trim(fgets($handle));

while($number >= 0){

  $word = trim(fgets($handle));
  $length = strlen($word);
  echo $length > 10 ? $word[0]. ($length - 2) . $word[$length - 1]."\r" : $word."\r";
  $number--;

}

fclose($handle);

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

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

for($i=0 ; $i<$n ; $i++)
{
     fscanf( $stdin , "%s" , $s ) ;
     if( strlen( $s ) > 10 )
     {
          echo $s[0] . "" . ( strlen($s)-2 ) . "" . $s[ strlen($s)-1] . "\n" ;
     }
     else
     {
          echo $s . "\n" ;
     }
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
error_reporting(E_ALL);

function solve($word)
{
    $word = preg_replace('/\s+/', '', $word);
    if (strlen($word) > 10) {
        if (!ctype_digit($word)) {
            $first = $word{0};
            $last = substr($word, -1);
            return $first . (strlen($word) - 2) . $last;
        }
    } else {
        if (!ctype_digit($word)) {
            return $word;
        }
    }
}

while ($word = fgets(STDIN)) {
    echo solve($word).PHP_EOL;
}
?>

<?php
$count = (int) trim(fgets(STDIN));
for ($i = 0; $i < $count; $i++) {
    $word = trim(fgets(STDIN));
    if (($num = strlen($word)) > 10) {
        $word = $word[0] . ($num-2) . $word[$num - 1];
    }
    echo $word."\n";
}

<?php
$number = readline("Enter a number: ");
$words = array();
if ($number>=1 && $number <=100){
    while ($number--!=0){
        $word = readline("Enter a word: ");
        if (strlen($word)>=1 && strlen($word)<=100){
            $words[] = $word;
        }
    }
}
foreach ($words as $w) {
    $length = strlen($w);
    if ($length<=10){
        echo $w."\n";
    } else {
        echo $w[0].($length-2).$w[$length-1]."\n";
    }
}
?>

<?php
list($n)=explode(" ",trim(fgets(STDIN)));
for ($i=0;$i<$n;$i++){
list($a)=explode(" ",trim(fgets(STDIN)));
$num=strlen("$a");
if ($num<=10) print("$a\r\n");
else {$first=substr($a,0,1);
$last=substr($a,-1);
$num-=2;
print"$first$num$last\n";}
}
?>

<?php
$input = array();
$tirms = trim(fgets(STDIN));
for($i=0; $i<$tirms; $i++)
	$input[$i] = trim(fgets(STDIN));

foreach ($input as $value)
{
	$num = strlen($value);
	if ($num <= 10)
		$out = $value;
	else
	{
		$n = $num-2;
		$out = substr($value, 0, 1).$n.substr($value, -1, 1);
	}

	echo $out;
	echo "\n";
}

?>

<?php
    $input = file_get_contents('php://stdin');
    $arr = explode("\r\n", $input);
    for ($i = 0; $i < count($arr); $i++) {
        if ($i == 0) continue;
        echo ((strlen($arr[$i]) > 10)? substr($arr[$i], 0, 1) . (strlen($arr[$i])-2) . substr($arr[$i], -1) : $arr[$i]) . (($i != count($arr) - 1)? "\r\n" : "");
    }
?>

<?php fscanf ( STDIN, '%d', $num1 ); while ( fscanf ( STDIN, '%s', $var1) ) { $num = strlen ( $var1 ); if ($num > 10) { 	$var1 = $var1[0] . ($num-2) . $var1[$num-1]; } echo $var1 . "\n";} ?>

<?php

function read_words() {

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

	while ($n--) {
		fscanf(STDIN, "%s", $w);
		$words[] = $w;
	}

	return $words;
}

function abbreviate_words($words) {
	return array_map(
		function ($w) {
			$l = strlen($w);
			return $l > 10 ? $w[0] . ($l - 2) . $w[$l - 1] : $w;
		},
		$words
	);
}

$words = read_words();
$abbr_words = abbreviate_words($words);

print_r(implode("\n", $abbr_words));

<?php
    fscanf(STDIN,'%d',$no_word);
    for ($i=0; $i<$no_word; $i++) {
        fscanf(STDIN,'%s',$word);
        $length = strlen($word);
        if (strlen($word) <= 10) {
            echo $word . "\n";
        } else {
            echo substr($word,0,1) . ($length-2) . substr($word,$length-1,1) . "\n";
        }
    }
?>

<?php
$f = fopen("php://stdin", "r");
$g = trim(stream_get_contents($f));
$in = explode("\n", $g);

for ($i = 0; $i < count($in); $i++) {
  if(!is_numeric(trim($in[$i]))){
    $item = trim($in[$i]);
    $l = strlen($item);
    if ($l > 10) {
      $x = str_split($item);
      echo $x[0] . ($l - 2) . $x[$l - 1];
    } else {
      echo $item;
    }
    echo "\n";
  }
}

<?php
/**
 * Secdra @2020
 */
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%s", $word);
    if (strlen($word) > 10) {
        printf("%s%d%s", $word[0], strlen($word) - 2, $word[-1]);
    } else {
        printf("%s", $word);
    }
    printf("\n");
}
?>

<?php

function read_words() {

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

	while ($n--) {
		fscanf(STDIN, "%s", $w);
		$words[] = $w;
	}

	return $words;
}

function abbreviate_words($words) {
	return array_map(function ($w) {
		$l = strlen($w);
		if ($l > 10) {
			return $w[0] . ($l - 2) . $w[$l - 1];
		} else {
			return $w;
		}
	}, $words);
}

function print_words($words, $split) {

	foreach ($words as $w) {
		echo $w . "\n";
	}
	echo "\n";
}

$words = read_words();
$abbr_words = abbreviate_words($words);

print_words($abbr_words, "\n");

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if(strlen($b) > 10)
     {
          print $b[0] . (strlen($b) - 2) . $b[strlen($b) - 1] . "\n";
     }
     else
     {
          print $b . "\n";
     }
}
?>

<?php

function read_words() {

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

	while ($n--) {
		fscanf(STDIN, "%s", $w);
		$words[] = $w;
	}

	return $words;
}

function abbreviate_words($words) {
	return array_map(function ($w) {
		$l = strlen($w);
		if ($l > 10) {
			return $w[0] . ($l - 2) . $w[$l - 1];
		} else {
			return $w;
		}
	}, $words);
}

function print_words($words, $split) {
	print_r(implode($split, $words));
}

$words = read_words();
$abbr_words = abbreviate_words($words);
print_r(implode("\n", $abbr_words));
// print_words($abbr_words, "\n");

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
$read = read();
$x = explode("\n", $read);

$out = [];
foreach($x as $k=>$line){
	if($k != 0){
		$out[] = strlen($line)<=11?$line:substr($line, 0,1).(strlen($line)-3).substr($line, strlen($line)-2);
	}
}
put(implode("\n",$out));
?>

<?php
$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) <= 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
// print_r(($dataClear));
for($i = 0; $i < $amount ; $i++){
    if($dataClear[$i] == max(array_keys($dataClear))){
        echo($dataClear[$i]);
    }else{
        echo($dataClear[$i])."\n";
    }
}
?>

<?php
$lines = (int)fgets(STDIN);
if($lines >= 1 && $lines <= 100)
{
    $words = [];
    for($i = 0;$i < $lines; $i++)
        $words[$i] = fgets(STDIN);
    foreach($words as $word)
    {
        if(strlen($word) > 12)
            echo $word[0]."".(strlen($word) - 4) ."".$word[-3]."\n";
        else
            echo $word;

    }
}
else
{
    echo "Not valid input\n";
}

?>

<?php

$is_first = true;
while ($row = fgets(STDIN)) {
    if ($is_first === true) {
        $is_first = false;
        continue;
    }
    $length = strlen($row) - 2;
    if ($length > 10) {
        echo $row[0] . ($length - 2) . $row[$length - 1] . "\n";
    } else {
        echo $row . "\n";
    }
}

<?php

$input = trim(fgets(STDIN));
$numberOfInputs = (int)$input;

$resultArray = array();

for ($count = 0; $count < $numberOfInputs; $count++) {
    $string = trim(fgets(STDIN));
    $length = strlen($string);
    if ($length > 10) {
        $result = "{$string[0]}" . ($length-2) . "{$string[$length - 1]}";
        array_push($resultArray, $result);
    } else {
        array_push($resultArray, $string);
    }
}
foreach ($resultArray as $result) {
    printf("%s\n",$result) ;
}

<?php
function longWord($in,$arr){

    for($i=0;$i<$in;$i++){
       if(strlen($arr[$i])<=10)
       echo $arr[$i]."\n";
       else
       echo substr($arr[$i],0,1).(strlen($arr[$i])-2).substr($arr[$i],strlen($arr[$i])-1,1)."\n";
    }
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$in);
$arr=array();
for($i=0;$i<$in;$i++){
    fscanf($stdin, "%s", $arr[$i]);
}
longWord($in,$arr);
?>

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

     function reduceStr($i)
     {
         $arr = str_split($i);
         $num = count($arr) - 2;
         if(count($arr) <= 10){
             echo $i;
         }else{
             echo $arr[0] . $num . $arr[$num + 1];
         }
     }

    for($i =  0; $i < count($b); $i++){
        reduceStr($b[$i]);
        echo PHP_EOL;
    }

?>

<?php
fscanf(STDIN, "%d", $n);
while($n--)
{
    fscanf(STDIN, "%s", $s);
    $ln = strlen($s) - 2;
    echo $ln > 8 ? $s[0].$ln.$s[$ln+1]:$s;
    echo "\n";
}
?>

<?php
$n = (int)fgets(STDIN);

$words = array();

for ($i = 1; $i <= $n; $i++) {
    $words[$i] = trim(fgets(STDIN));
}

for ($i = 1; $i <= $n; $i++) {
    $word = $words[$i];
    if (strlen($word) > 10) {
        echo substr($word, 0, 1) . (strlen($word) - 2) . substr($word, -1, 1);
    } else {
        echo $word;
    }
    echo "\n";
}

<?php

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

$n = trim(fgets(STDIN));

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

	$str = trim(fgets(STDIN));
	$len = strlen($str);

	if ( $len > 10 ) {
		echo $str{0} . ($len - 2) . $str{$len - 1};

	} else {
		echo $str;
	}

	echo "\n";
}

<?php
fscanf(STDIN, "%d", $length);
for($i = 0; $i < $length; $i ++) {
    fscanf(STDIN, "%s", $s);
    $strLength = strlen($s);
    if($strLength > 10) {
        echo $s[0] . ($strLength-2) . $s[$strLength-1] . "\n";
    } else {
        echo $s . "\n";
    }
}

<?php
// 71A Слишком длинные слова

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

$input_line = fgets($in);

$n = (int) $input_line;
$out = '';

for ($i = 1; $i <= $n; $i++ ) {

    $input_line = fgets($in);
    $len = strlen($input_line);
    if ($len < 13) {
        $out .= $input_line;
    } else {
        $out .= $input_line[0] . (string)($len - 4) . substr($input_line, $len - 3, 3);
    }
    // $out .= '\n';
}

echo $out;

?>

<?php
$_fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
fscanf($_fp,"%d",$num);

for ($i=0; $i < $num; $i++) {
    fscanf($_fp, "%s", $text[$i]);
}

for ($i=0; $i < $num; $i++) {
    if(strlen($text[$i]) > 10)
    {
        $textArray = str_split($text[$i]);

        $countString = strlen($text[$i]);

        $stringAkhir = $text[$i][$countString - 1];

        $splice = $countString - 2;

        array_splice($textArray, 1, $splice);

        for ($j=0; $j < 2; $j++) {
            array_splice($textArray, $j + 1, 0, strval($splice)[$j]);
        }
        echo implode($textArray) . "\n";
    } else {
        echo $text[$i] . "\n";
    }
}
?>

<?php
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$n);
for($i = 0; $i < $n; $i++)
{
    fscanf($stdin, "%s",$s);
    if(strlen($s) > 10) {
        echo $s[0].(strlen($s) - 2).$s[strlen($s) -1 ]."\n";
    } else {
        echo $s."\n";
    }
}

<?php

$num = readline();

for($i = 0; $i < $num; $i++) {
    $str = readline();

    $len = strlen($str);

    if($len > 10) {
        echo $str[0] . ($len - 2) . $str[$len-1] .  "\n";
    } else {
        echo $str . "\n";
    }

}

<?php
	//fopen("php://stdin");
	//$n=+readline();
	//fopen("php://stdout");
	fscanf(STDIN,"%d",$n);
	for($i=0;$i<$n;$i++)
	{
		//$str=readline();
		fscanf(STDIN,"%s",$str);
		if (strlen($str)<=10)echo "$str\n";
		else
		{
			$l=strlen($str)-2;
			$ans=$str[0].strval($l).$str[$l+1];
			echo $ans."\n";
		}
	}

?>

<?php
fscanf(STDIN, "%d", $s);
while(fscanf(STDIN, "%s", $s))
{
    $ln = strlen($s) - 2;
    echo $ln > 8 ? $s[0].$ln.$s[$ln+1]:$s;
    echo "\n";
}
?>

<?php
class LongWords {
    public function getResult($str) {
        $str = str_replace(' ', '', $str);
        $lowercase = strtolower($str);
        $strlen = strlen($lowercase);
        //print $strlen;
        if($strlen >= 1 && $strlen <= 100) {
            if($strlen > 10) {
                $eachstr = str_split($lowercase);
                $strlen = $strlen - 1;
                $result = $strlen - 1;
                return $eachstr[0].$result.$eachstr[$strlen];
            } else{
                if(!is_numeric($lowercase)) {
                    return $lowercase;
                }
                return false;
            }
        }
        return false;
    }
}
$obj = new LongWords();

function getinput() {
    return trim(fgets(STDIN));
}

$t = (int)getinput();
// print gettype($t);
while($t--) {
    print $obj->getResult(getinput())."\n";
}

<?php
$count = fgets(STDIN);
for($i = 0; $i < $count; $i++){
$string = trim(fgets(STDIN));

if(strlen($string)<=10){
print($string."\r\n");
continue;
}
$tmp_string = $string{0}.(strlen($string)-2).$string{strlen($string)-1};

print($tmp_string."\r\n");

}
?>

<?php
$input = array();
$tirms = trim(fgets(STDIN));
for($i=0; $i<$tirms; $i++)
	$input[$i] = trim(fgets(STDIN));

foreach ($input as $value)
{
	$num = strlen($value);
	if ($num <= 10)
		$out = $value;
	else
	{
		$n = $num-2;
		$out = substr($value, 0, 1).$n.substr($value, -1, 1);
	}

	echo $out;
	echo "\n";
}

?>

<?php
fscanf(STDIN, '%d', $n);
while(fscanf(STDIN, '%s', $s)) {
	$l = strlen($s);
	if ($l > 10) {
		echo substr($s, 0, 1),($l-2),substr($s,-1),PHP_EOL;
	} else { echo $s,PHP_EOL;}
}
?>

<?php

    $n = trim(fgets(STDIN));
    $arr = [];
    for($i = 0; $i < $n; $i++) {
        $w = trim(fgets(STDIN));
        if (strlen($w) > 10) {
            $length = strlen($w);
            $e = substr($w, -1);
            $a = $w[0] . (string)($length - 2) . $e;
            echo($a . PHP_EOL);
        } else {
            //$arr[$i] = $w;
            echo($w . PHP_EOL);
        }
    }

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     if(strlen($b) > 10)
     {
          print $b[0] . (strlen($b) - 2) . $b[strlen($b) - 1] . "\n";
     }
     else
     {
          print $b . "\n";
     }
}
?>

<?php
	fscanf(STDIN, "%d", $n);
	while($n--)
	{
			fscanf(STDIN, "%s", $word);
			$len=strlen($word);
			if ($len <= 10)
			{
				echo $word . "\n";
			}
			else
			{
				echo $word[0] . ($len-2) . ($word[$len-1]) . "\n";
			}
	}
?>

<?php
// https://codeforces.com/problemset/problem/71/A
fscanf(STDIN, "%d", $n);
for($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%s", $s);
	$in = strlen($s);
	echo $in <= 10 ? $s . "\n" : $s[0] . ($in-2) . $s[$in-1] . "\n";
}

<?php
    fscanf(STDIN,'%d',$no_word);
    for ($i=0; $i<$no_word; $i++) {
        fscanf(STDIN,'%s',$word);
        $length = strlen($word);
        if (strlen($word) <= 10) {
            echo $word . "\n";
        } else {
            echo substr($word,0,1) . ($length-2) . substr($word,$length-1,1) . "\n";
        }
    }
?>

<?php

$stdin = fopen('php://stdin', 'r');
$line1 = fgets($stdin);
$arr=explode(' ',$line1);
$n=$arr[0];

$stdout=fopen('php://stdout','w');
for ($i=0;$i<$n;$i++)
{
    $line = trim(fgets($stdin));
    if (strlen($line)<=10) {$good=$line;} else {$good=$line[0].(strlen($line)-2).$line[strlen($line)-1];}

    $r[$i]=$good."\n";
}

for ($i=0;$i<$n;$i++)
{
    fwrite($stdout,$r[$i]);
}

fclose($stdin);

//fwrite($stdout,$n);
fclose($stdout);

?>

<?php
    $input = file_get_contents('php://stdin');
    $arr = explode("\r\n", $input);
    for ($i = 0; $i < count($arr); $i++) {
        if ($i == 0) continue;
        echo ((strlen($arr[$i]) > 10)? substr($arr[$i], 0, 1) . (strlen($arr[$i])-2) . substr($arr[$i], -1) : $arr[$i]) . (($i != count($arr) - 1)? "\r\n" : "");
    }
?>

<?php
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$in = trim(fgets(STDIN));
		$len = strlen($in);
		if ($len > 10) {
			echo $in[0].($len-2).$in[$len-1].PHP_EOL;
		} else {
			echo $in.PHP_EOL;
		}
	}
?>

<?php
	$n = trim(fgets(STDIN));
	$i = 0;
	while($i<$n)
	{
		$str = trim(fgets(STDIN));
		$pjg = strlen($str);
		echo ($pjg <= 10)?$str:substr($str,0,1) . ($pjg-2) . substr($str,-1);
		echo "\n";
		$i++;
	}
?>

<?php
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%s",$words[]);
	if (strlen($words[$i])>10) {
	$words[$i]=$words[$i][0].(strlen($words[$i])-2).$words[$i][strlen($words[$i])-1];
}
}
for ($i=0; $i < $n; $i++) {
	echo "$words[$i]\n";
}
?>

<?php
fscanf(STDIN , "%d",$s);
for($i = 0 ; $i < $s ; $i++){

fscanf(STDIN , "%s",$str);

if(strlen($str) <= 10){
	echo $str."\n";
}else{
	echo $str[0].(strlen($str)-2).$str[strlen($str)-1]."\n";
}

}
?>

<?php
// for example, the input is '5 9'
$result = trim(fgets(STDIN));
list($n) = explode(' ',$result);
for($n;$n > 0;$n--){
    $word = trim(fgets(STDIN));
    $wLen = strlen($word);
    if($wLen > 10)
    {
        echo $word[0] . ($wLen -2 ) . $word[$wLen-1] . "\n";
    }
    else echo $word . "\n";
}
// there will be 14
?>

<?php

//fscanf(STDIN, "%d\n", $number); // reads number from STDIN
$number = trim(fgets(STDIN)); // reads one line from STDIN
$i=0;

while($i<$number && $line= trim(fgets(STDIN))){

    $str = $line;
    $ln = strlen($str) ;

    if($ln>10){
        fwrite(STDOUT, $str[0].($ln-2).$str[$ln-1]."\n");
    }else{
        fwrite(STDOUT, $str."\n");
    }
}

<?php

$numOfLines = readline();
$inputs = array();

for($i = 0 ; $i < $numOfLines ; $i++){
    $input = readline();
    $inputs[] = $input ;
}

foreach($inputs as $result){
    $numOfChar = strlen($result) ;
    if($numOfChar > 10){
        $firstChar = $result[0];
        $lastChar = $result[$numOfChar - 1] ;
        echo "\n".$firstChar.($numOfChar-2).$lastChar ;
    }else{
        echo "\n".$result ;
    }

}

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) - 2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
for($i = 0; $i < $amount; $i++){
    echo($dataClear[$i]);
}

<?php

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

// $input = '3
// 1 0 1
// 0 1 1
// 0 0 0';

$arr = explode(PHP_EOL, $input);
for($i=0;$i<$arr[0];$i++){
    if(strlen($arr[$i+1]) < 10)
        echo $arr[$i+1];
    else{
        $str = $arr[$i+1];
        $str_sc = $str[0];
        $str_sc .= strlen($str) - 2;
        $str_sc .= $str[strlen($str)-2];
        echo $str_sc . '\n';
    }
}

<?php
fscanf(STDIN,"%d", $n);

while($n > 0)
{
	fscanf(STDIN, "%s", $w);
	if(strlen($w) < 11)
		fprintf(STDOUT, "%s". $w);
	else
		fprintf(STDOUT, "%s", $w[0] . (strlen($w) - 2) . $w[strlen($w)-1]);
	$n--;
}

<?php
// Open the file
//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');
$file = fopen("php://stdin", 'r');

// Add each line to an array
if ($file) {
//    $array = explode("\n", fread($file, filesize("C:\\xampp\\htdocs\\test\\test.txt")));
    $array = explode("\n", fread($file, filesize("php://stdin")));

    array_shift($array);
    $array = array_values($array);
    $array=preg_replace('/\s+/', '', $array);

    foreach ($array as $key => $value){

//        echo $value;
        if(strlen($value) < 10 ) echo $value;
        else{
            //
            echo $value[0];
            echo strlen($value) - 2;
            echo substr("$value", -1); // returns last
        }

        echo "\n";
    }
//    fclose($file);

}
?>

<?php
fscanf(STDIN, "%d", $s);
while (fscanf(STDIN, "%s", $s)) {
    $ln = strlen($s) - 2;
    echo $ln > 8 ? $s[0].$ln.$s[$ln+1] : $s;
}

<?
$n=fgets(STDIN);
for($i=0;$i<$n;$i++)
    {
        $nam = fgets(STDIN);
        $ln = strlen($nam);
        $lc = strlen($nam);
        if($ln>8) echo substr($nam,0,1).$ln.substr($nam,$lc);
         else echo $nam;
    }
?>

<?php
$count = fgets(STDIN);
for($i = 0; $i < $count; $i++){
$string = trim(fgets(STDIN));

if(strlen($string)<=10) continue;

$tmp_string = $string{0}.(strlen($string)-2).$string{strlen($string)-1};

print($tmp_string."\r\n");

}
?>

<?php

// php://input or input.txt or STDIN
$input = STDIN;

// php://output or output.txt or STDOUT
$output = STDOUT;

define('MAX_LENGTH', 10);

function foo($s)
{
    $sl = strlen($s);

    if ($sl > MAX_LENGTH) {
        return $s[0] . ($sl - 2) . $s[$sl - 1];
    }

    return $s;
}

$results = [];

$n = fread($input, 3);

for ($i = 0; $i < $n; $i++) {
    $s = trim(fread($input, 100));

    $r = foo($s);

    if ($i + 1 < $n) {
        $r .= PHP_EOL;
    }

    fwrite($output, $r);
}

<?php
$handle = fopen ("php://stdin","r");
$word = fgets($handle);
$length = strlen($word);
if($length <= 5){
  echo $word;
}else{
  echo $word[0]. ($length - 3) . $word[$length - 2];
}

fclose($handle);

<?php
// for example, the input is '5 9'
$result = trim(fgets(STDIN));

list($n) = explode(' ',$result);
for($n;$n > 0;$n--){
    $word = trim(fgets(STDIN));
    $wLen = strlen($word);
    if($wLen > 10)
    {
        echo $word[0] . ($wLen -2 ) . $word[$wLen-1];
    }
    else echo $word;
}

// there will be 14
?>

<?php

function read_words() {

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

	while ($n--) {
		$words[] = explode(" ", trim(fgets(STDIN)));
	}

	return $words;
}

function abbreviate_words($words) {
	return array_map(function ($w) {
		$l = strlen($w) - 2;
		if ($l > 10) {
			return $w[0] . ($l - 2) . $w[$l - 1];
		} else {
			return $w;
		}
	}, $words);
}

function print_words($words, $split) {
	foreach ($words as $w) {
		echo $w;
	}
	echo "\n";
}

$words = read_words();
$abbr_words = abbreviate_words($words);

print_words($abbr_words, "\n");

<?php

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}

for($i = 0; $i < count($dataClear); $i++){
    echo($dataClear[$i])."\n";
}

?>

<?php

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)));
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
for($i = 0; $i < $amount; $i++){
    echo($dataClear[$i])."\n";
}

?>

<?php

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

$number = (int)fgets($handle);

while($number >= 0){

  $word = fgets($handle);

  $length = strlen($word);

  if($length <= 10){

    echo $word."\n";

  }else{

    echo $word[0]. ($length - 3) . $word[$length - 2]."\n";

  }

  $number--;
}

fclose($handle);

<?
$n=fgets(STDIN);
for($i=0;$i<$n;$i++)
    {
        $nam = fgets(STDIN);
        $ln = strlen($nam);
        if($ln>10){
            echo substr($nam,0,1);
            echo ($ln)-2;
            echo substr($nam,-1);
          }
         else echo $nam;
    }
?>

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	if ($len > 10) {
		echo $in[0].$len.$in[$len-1];
	} else {
		echo $in;
	}
?>

<?php
fscanf(STDIN, '%d', $a);
for ($i=0 ; $i<$a ; $i++ ){
    fscanf(STDIN, '%s', $word);
    $b =strlen($word);
    if ($b >= 10) {
        echo $word[0].($b-2).$word[strlen($word)-1] , "
";
    }
    else{echo $word ,"
";}
}

<?

$str = explode("\n", STDIN);
array_shift($str);

foreach ($str as $i => $word)
{
    if(strlen($word) > 10)
    {
        echo substring($word, 0,1) . (strlen($word)-2) . substring($word, -1) . PHP_EOL;
    }
}

<?php
// 71A Слишком длинные слова

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

$input_line = fgets($in);

$n = (int) $input_line;
$out = '';

for ($i = 1; $i <= $n; $i++ ) {

    $input_line = fgets($in);
    $len = strlen($input_line);
    if ($len <= 10) {
        $out .= $input_line;
    } else {
        $out .= $input_line[0] . (string)($len - 2) . $input_line[$len - 1];
    }
    $out .= '\n';
}

echo $out;

?>

<?php
function longWord($in){
    $arr=array();
    for($i=0;$i<$in;$i++){
        $stdin = fopen("php://stdin","r");
        fscanf($stdin,"%d",$arr);
    }
    for($i=0;$i<$in;$i++){
       if(strlen($arr[$i])<=10)
       echo $arr[$i]."
";
       else
       echo substr($arr[$i],0,1).(strlen($arr[$i])-2).substr($arr[$i],strlen($arr[$i])-1,1)."
";
    }
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$in);
longWord($in);
?>

<?php
$n = trim(fgets(STDIN));
for($i=1;$i<=$n;$i++)
{
    $var = fgets(STDIN);
    if (strlen($var) > 10) {
        echo $var[0] . (strlen($var)-2) . $var[strlen($var)-1];
    }
    else{
        echo $var;
    }
}

<?php
    $arr = explode("\r\n", fgets(STDIN));
    $lengthLimit = $arr[0];
    for ($i=1; $i < count($arr); $i++){
        if (strlen($arr[$i])>$lengthLimit) {
            preg_match("/(.{1})(.+)(.{1})/", $arr[$i], $outArr);
            echo $outArr[1].((string)strlen($outArr[2])).$outArr[3];
        } else {
            echo $arr[$i];
        }
    }

<?php

$num =fgets(STDIN);
for($i=1 ; $i<=$num ; $i++){
$str =fgets(STDIN);
$num1 =strlen($str);
$num2 =$num1-4;
if($num1>10){
echo $str[0]. $num2 . $str[$num1-3] ."\n" ;
}
else {
echo $str ."\n";
}
}

?>

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

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

// Take inputs
for ($i = 0; $i < $n; $i++) {
	fscanf($fr, "%s", $words[]);
}

foreach($words as $key => $word) {
	if (strlen($word) < 10) {
		fprintf($fw, $word . "\n");
	} else {
		fprintf($fw, abbreviation($word) . "\n");
	}

}

function abbreviation($word)
{
	$firstChar = $word[0];
	$lastChar = substr($word, -1);

	return $firstChar . (strlen($word) - 2) . $lastChar;
}

fclose($fr);
fclose($fw);

<?php

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

$number = (int)fgets($handle);

while($number >= 0){

  $word = fgets($handle);

  $length = strlen($word);

  if($length > 11){

    echo $word[0]. ($length - 4) . $word[$length - 3];

  }else{

    echo $word;

  }

  $number--;
}

fclose($handle);

<?
$n=fgets(STDIN);
for($i=0;$i<$n;$i++)
    {
        $nam = fgets(STDIN);
        if(strlen($nam)>10){
            echo substr($nam,0,1);
            echo strlen($nam)-2;
            echo substr($nam,-1);
          }
         else echo $nam;
    }
?>

<?php
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$in = trim(fgets(STDIN));
		$len = strlen($in);
		if ($len > 10) {
			echo $in[0].($len-2).$in[$len-1].'\n';
		} else {
			echo $in.'\n';
		}
	}
?>

fscanf(STDIN, "%d", $length);
for($i = 0; $i < $length; $i ++) {
    fscanf(STDIN, "%s", $s);
    $strLength = strlen($s);
    if($strLength > 10) {
        echo $s[0] . $s[$strLength-1];
    } else {
        echo $s;
    }
}

<?
$n = trim(fgets(STDIN));
for($i=0;$i<$n;$i++){
    $str = trim(fgets(STDIN));
    if(strlen($str)>10){
        $fstr .= $str[0] .  strlen($str)-2 . $str[strlen($str)-1] . "/n";
    }
    else{
        $fstr .= $str;
    }
}
print $fstr;

<?php

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
$counter;
if($amount < count($dataClear)){
    $counter = $amount;
}else{
    $counter = count($dataClear);
}

for($i = 0; $i < $counter ; $i++){
    if($dataClear[$i] == end($dataClear)){
        echo($dataClear[$i]);
    }else{
        echo($dataClear[$i])."\n";
    }
}
?>

<?php
function longWord($in){
    $arr=array('word','localization','internationalization','pneumonoultramicroscopicsilicovolcanoconiosis');
    // for($i=0;$i<$in;$i++){
    //     fscanf(STDIN, "%d", $arr[$i]);
    // }
    for($i=0;$i<$in;$i++){
       if(strlen($arr[$i])<=10)
       echo $arr[$i]."
";
       else
       echo substr($arr[$i],0,1).(strlen($arr[$i])-2).substr($arr[$i],strlen($arr[$i])-1,1)."
";
    }
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$in);
longWord(4);
?>

<?php

$input = trim(fgets(STDIN));
$numberOfInputs = (int)$input;

$resultArray = array();

for ($count = 0; $count < $numberOfInputs; $count++) {
    $string = trim(fgets(STDIN));
    $length = strlen($string);
    if ($length > 10) {
        $result = "{$string[0]}" . $length . "{$string[$length - 1]}";
        array_push($resultArray, $result);
    } else {
        array_push($resultArray, $string);
    }
}
foreach ($resultArray as $result) {
    printf("%s\n",$result) ;
}

<?php
fscanf(STDIN, '%d', $a);
for ($i=0 ; $i<$a ; $i++ ){
    fscanf(STDIN, '%s', $word);
    $b =strlen($word);
    if ($b >= 10) {
        echo $word[0].($b-2).$word[strlen($word)-1] , '
';
    }
    else{echo $word ,'
';}
}

<?php fscanf ( STDIN, '%d', $num1 ); while ( fscanf ( STDIN, '%s', $var1) ) { $num = strlen ( $var1 ); if ($num > 10) { 	$var1 = $var1[0] . ($num-2) . $var1[$num-1]; } echo $var1;} ?>

<?php

fscanf(STDIN, "%d\n", $number);
if ($number >= 1 && $number <= 100) {
    for ($i=1; $i <= $number; $i++) {
        $line[$i] = trim(fgets(STDIN));
    }
    for ($i=1; $i <= $number; $i++) {
        if (strlen($line[$i]) > 10) {
        print(substr_replace($line[$i], strlen($line[$i])-2, 1, strlen($line[$i])-2) . "\n");
        } else { print ($line[$i]);}
    }
}

<?php
$n = trim(fgets(STDIN));
for($i=1;$i<=$n;$i++)
{
    $var = fgets(STDIN);
    if (strlen($var) > 10) {
        $w = $var[0].(strlen($var)-2).$var[strlen($var)-1];
        echo $w;
    }
    else{
        echo $var;
    }
}

<?php

$str = explode("\n", STDIN);
array_shift($str);

foreach ($str as $i => $word)
{
    if(strlen($word) > 10)
    {
        echo substr($word, 0,1) . (strlen($word)-2) . substr($word, -1) . PHP_EOL;
    }
}

<?php
fscanf(STDIN,"%d", $n);

while($n > 0)
{
	fscanf(STDIN, "%s", $w);
	if(strlen($w) < 11)
		fprintf(STDOUT, "%s", $w);
	else
		fprintf(STDOUT, "%s", $w[0] . (strlen($w) - 2) . $w[strlen($w)-1]);
	$n--;
}

<?php
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$in = trim(fgets(STDIN));
		$len = strlen($in);
		if ($len > 10) {
			echo $in[0].($len-2).$in[$len-1];
		} else {
			echo $in;
		}
	}
?>

<?php
$j = fgets(STDIN);
while($s = fgets(STDIN)) $arr[] = $s;
foreach($arr as $s) {
    if(strlen($s)>10) {
        echo $s{0}.(strlen($s)-2).$s{strlen($s)-1}."\n";
    } else echo $s."\n";
}
?>

<?php

$input=fgets(STDIN);

$s=strlen($input);
$ss=$s - 2;

echo $input[0].$ss.$input[strlen($input) - 1];

?>

<?php
$f = fopen("php://stdin", "r");
$g = trim(stream_get_contents($f));
$in = explode("\n", $g);

for ($i = 0; $i < count($in); $i++) {
  if(!is_numeric($in[$i])){
    $item = trim($in[$i]);
    $l = strlen($item);
    if ($l > 10) {
      $x = str_split($item);
      echo $x[0] . ($l - 2) . $x[$l - 1];
    } else {
      echo $item;
    }
    echo "\n";
  }
}

<?php

// php://input or input.txt or STDIN
$input = STDIN;

// php://output or output.txt or STDOUT
$output = STDOUT;

define('MAX_LENGTH', 10);

function foo($s)
{
    $sl = strlen($s);

    if ($sl > MAX_LENGTH) {
        return $s[0] . ($sl - 2) . $s[$sl - 1];
    }

    return $s;
}

$n = (int)trim(fgets($input, 3));

for ($i = 0; $i <= $n; $i++) {
    $s = trim(fgets($input, 101));

    $r = foo($s);
    $r .= PHP_EOL;

    echo ltrim($r);
}

<?php
fscanf(STDIN, "%d", $d);
while (fscanf(STDIN, "%s", $s)) {
	if(strlen($s) <= $d){
		echo $s . '<br>';
		continue;
	}else{
		$t = strlen($s);
		echo $s[0];
		echo $t-2;
		echo $s[$t - 1];
	}
}

<?php

function read_words() {

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

	while ($n--) {
		fscanf(STDIN, "%s", $w);
		$words[] = $w;
	}

	return $words;
}

function abbreviate_words($words) {
	return array_map(function ($w) {
		$l = strlen($w);
		if ($l > 10) {
			return $w[0] . ($l - 2) . $w[$l - 1];
		} else {
			return $w;
		}
	}, $words);
}

function print_words($words, $split) {
	foreach ($words as $w) {
		echo $w;
	}
	echo "\n";
}

$words = read_words();
$abbr_words = abbreviate_words($words);

print_words($abbr_words, "\n");

<?php

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

// $input = '3
// 1 0 1
// 0 1 1
// 0 0 0'

$arr = explode(PHP_EOL, $input);
for($i=0;$i<$arr[0];$i++){
    if(strlen($arr[$i+1]) < 10) {
        echo $arr[$i+1];
    }
    else{
        $str = $arr[$i+1];
        $str_sc = $str[0];
        $str_sc .= strlen($str) - 2;
        $str_sc .= $str[strlen($str)-2];
        echo $str_sc . '\n';
    }
}

<?php
function longWord($in){
    $arr=array();
    for($i=0;$i<$in;$i++){
        $stdin = fopen("php://stdin","r");
        fscanf($stdin,"%d",$arr[$i]);
    }
    for($i=0;$i<$in;$i++){
       if(strlen($arr[$i])<=10)
       echo $arr[$i]."
";
       else
       echo substr($arr[$i],0,1).(strlen($arr[$i])-2).substr($arr[$i],strlen($arr[$i])-1,1)."
";
    }
}
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%d",$in);
longWord($in);
?>

<?php
$str = fgets(STDIN);
while ($str = fgets(STDIN)) {
    if(!is_numeric($str)){
        if(strlen($str) > 10){
            echo substr($str, 0,1).(strlen($str)-4).substr($str, strlen($str)-3,1).PHP_EOL;
        }else{
            echo $str.PHP_EOL;
        }
    }
}
?>

<?php

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

// $input = '3
// werwer
// werwer
// qwrqwerqwerqwerwqrr';

$arr = explode(PHP_EOL, $input);

for($i=1;$i<=$arr[0];$i++){
  if(strlen($arr[$i]) < 10)
    echo $arr[$i] . "\n";
  else{
    $str = $arr[$i][0];
    $str .= strlen($arr[$i])-2;
    $str .= $arr[$i][strlen($arr[$i])-1];
    echo $str;
  }
}

<?php

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

// $input = '3
// 1 0 1
// 0 1 1
// 0 0 0';

$arr = explode(PHP_EOL, $input);
for($i=0;$i<$arr[0];$i++){
    if(strlen($arr[$i+1]) < 10)
        echo $arr[$i+1];
    else{
        $str = $arr[$i+1];
        $str_sc = $str[0];
        $str_sc .= strlen($str) - 3;
        $str_sc .= $str[strlen($str)-2];
        echo $str_sc;
    }
}

<?php
    fscanf(STDIN,'%d',$no_word);
    for ($i=0; $i<$no_word; $i++) {
        fscanf(STDIN,'%s',$word);
        $length = strlen($word);
        if (strlen($word) < 10) {
            echo $word . "\n";
        } else {
            echo substr($word,0,1) . ($length-2) . substr($word,$length-1,1) . "\n";
        }
    }
?>

<?php
error_reporting(0);

function solve($word)
{
    if (strlen($word) > 10) {
        $first = $word{0};
        $last = $word{((int)strlen($word)-1)};
        return $first. (strlen($word) - 2) . $last;
    } else {
        if (!is_numeric($word)) {
            return $word;
        }
    }
}

$word = trim(fgets(STDIN));
echo solve($word);

?>

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

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

for($i=0 ; $i<$n ; $i++)
{
     fscanf( $stdin , "%s" , $s ) ;
     if( strlen( $s ) > 10 )
     {
          echo $s[0] . "" . ( strlen($s)-2 ) . "" . $s[ strlen($s)-2] . "\n" ;
     }
     else
     {
          echo $s . "\n" ;
     }
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
$n = readline('');
for($i=0;$i<$n;$i++){
	$word = readline('');
	if(strlen($word)>10){
		$first = $word[0];
		$last = $word[strlen($word)];
		$len = strlen($word)-2;
		echo $first.$len.$last."\n";
	}
	else{
	echo $word."\n";
	}
}

<?php
// Open the file
//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');
$file = fopen("php://stdin", 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", fread($file, filesize("php://stdin")));

    array_shift($array);
    $array = array_values($array);
    $array=preg_replace('/\s+/', '', $array);

    foreach ($array as $key => $value){

//        echo $value;
        if(strlen($value) < 10 ) echo $value;
        else{
            //
            echo $value[0];
            echo strlen($value) - 2;
            echo substr("$value", -1); // returns "s"
        }

//        echo "<br>";
    }
    fclose($file);

}
?>

<?php
fscanf(STDIN, '%d', $a) ;
$b = strlen($a);
if (gettype($a) == 'int') {
    die;
}
if ($b >= 10) {
    echo $a[0].($b-2).$a[strlen($a)-1];
}
else{echo $a;}

<?php

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

$word = fgets($handle);
$length = strlen($word);
if($length <= 10){
  echo $word;
}else{
  echo $word[0]. ($length - 3) . $word[$length - 2];
}

fclose($handle);

<?php
fscanf(STDIN,"%d", $n);

while($n > 0)
{
	fscanf(STDIN, "%s", $w);
	if(strlen($w) < 11)
		fprintf(STDOUT, "%s". $w);
	else
		fprintf(STDOUT, "%s", $w[0] . (strlen($w) - 2) . $w[strlen($w)-1]);
	$n--;
}
//

$a = fgets(STDIN);
echo $a{0}.(strlen($a)-2).$a{(strlen($a)-1)};

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	if ($len > 10) {
		echo $in[0].($len-2).$in[$len-1];
	} else {
		echo $in;
	}
?>

#!/usr/bin/python
# ------- start import ------- #
# import sys
# -------   end import ------- #

# ------- start main func ------- #
def main():
    # ------- start grab input ------- #
    word_no     = input()
    number      = 0
    words       = []
    for number in range (word_no):
        word = raw_input()
        print (word[0:4])
    # -------   end grab input ------- #

# -------   end main func ------- #

# ------- start declare main func ------- #
if __name__ == "__main__" : main()
# -------   end declare main func ------- #

<?php
$handle = fopen ("php://stdin","r");
$word = fgets($handle);
$length = strlen($word);
if($length <= 5){
  echo $word;
}else{
  echo $word[0]. ($length - 3) . $word[$length - 2];
}

fclose($handle);

<?php
fscanf(STDIN, "%d", $d);
while (fscanf(STDIN, "%s", $s)) {
	if(strlen($s) <= $d){
		echo $s . '<br>';
		continue;
	}else{
		$t = strlen($s);
		echo $s[0];
		echo $t-2;
		echo $s[$t - 1];
	}
}

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	if ($len > 10) {
		echo $in[0].$len.$in[$len-1];
	} else {
		echo $in;
	}
?>

<?php
$a = array();
$n = trim(fgets(STDIN));
for($i=0; $i<$n; $i++)
	$a[$i] = trim(fgets(STDIN));

foreach ($a as $value)
{
	$count = count($value);
	if ($count <= 10)
		$asw = $value;
	else
	{
		$c = $count-2;
		$asw = substr($value, 0, 1).$c.substr($value, -1, 1);
	}

	echo $asw;
	echo "\n";
}

<?php
    $n = fgets(STDIN);
    for ($i = 0; $i < $n; $i++){
        $st = fgets(STDIN);
        $st = str_replace('\r\n', '', $st);
        if (strlen($st) > 10) {
            $y = 2;
            if ($i == $n - 1) $y = 1;
            echo $st[0].(strlen($st) - 2).$st[strlen($st) - $y];
            echo PHP_EOL;
        } else echo $st;
    }
?>

<?php
$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
$counter;
if($amount < count($dataClear)){
    $counter = $amount;
}else{
    $counter = count($dataClear);
}
// echo(end($dataClear));
for($i = 0; $i < $counter ; $i++){
    if($dataClear[$i] == end($dataClear)){
        echo($dataClear[$i]);
    }else{
        echo($dataClear[$i])."\n";
    }
}
?>

<?php
	$n = trim(fgets(STDIN));
	$i = 0;
	while($i<$n)
	{
		$str = trim(fgets(STDIN));
		$pjg = strlen($str);
		echo ($pjg == $n)?$str:substr($str,0,1) . ($pjg-2) . substr($str,-1)."<br />";
		$i++;
	}
?>

<?php
	$in = fgets(STDIN);
	$len = strlen($in);
	if (is_numeric($in)) exit;
	if ($len > 10) {
		echo $in[0].($len-2).$in[$len-1].'\n';
	} else {
		echo $in.'\n';
	}
?>

<?php
//$stdin = fopen('php://stdin', 'r');
$stdin = (fgets(STDIN));
$str = explode("\n", $stdin);
if(count($str)>2){
  //  array_shift($str);

    foreach ($str as $i => $word)
    {
        if(strlen($word) > 10)
        {
            echo substr($word, 0,1) . (strlen($word)-2) . substr($word, -1) . PHP_EOL;
        }
    }
}
?>

<?php

$input = trim(fgets(STDIN));
$numberOfInputs = (int)$input;

$resultArray = array();

for ($count = 0; $count < $numberOfInputs; $count++) {
    $string = trim(fgets(STDIN));
    $length = strlen($string);
    if ($length > 10) {
        $result = "{$string[0]}" . $length . "{$string[$length - 1]}";
        array_push($resultArray, $string . "1");
    } else {
        array_push($resultArray, $string);
    }
}
foreach ($resultArray as $result) {
    echo $result . "<br>";
}

<?php

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
$counter;
if($amount < count($dataClear)){
    $counter = $amount;
}else{
    $counter = count($dataClear);
}
for($i = 0; $i < $counter ; $i++){

        echo($dataClear[$i]);
}
?>

<?php
$n = trim(fgets(STDIN));
for($i=1;$i<=$n;$i++)
{
    $w = fgets(STDIN);
    if (strlen($w) > 10) {
         $w=$w[0].(strlen($w)-2).$w[strlen($w)-1];
        echo $w;
    }

}

<?php
	$in = fgets(STDIN);
	$length = strlen($in);
	echo ($length>10)? $in[0].($length-2).$in[$length-1] : $in;
	echo "\n";
?>

<?php
$n = readline('');
for($i=0;$i<$n;$i++){
	$word = readline('');
	if(strlen($word)>10){
		$first = $word[0];
		$last = $word[strlen($word)];
		$len = strlen($word)-2;
		echo $first.$len.$last;
	}
}

<?php

// https://codeforces.com/problemset/problem/71/A

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

// word too long > 10 chars

$words = getStdIn();

foreach ($words as $key => $word) {
    if (($len = strlen($word)) > 10) {
        echo $word[0] . ($len - 2) . substr($word, -1) . PHP_EOL;
    } else {
        echo $word . PHP_EOL;
    }
}

<?php

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

// $input = '4
// word
// localization
// internationalization
// pneumonoultramicroscopicsilicovolcanoconiosis
// ';

$arr = explode(PHP_EOL, $input);

for($i=1;$i<=$arr[0];$i++){
  if(strlen($arr[$i]) < 10)
    echo $arr[$i] . "\n";
  else{
    $str = $arr[$i][0];
    $str .= strlen($arr[$i])-2;
    $str .= $arr[$i][strlen($arr[$i])-1];
    echo $str . "\n";
  }
}

<?php
fscanf(STDIN, '%d', $a);
for ($i=0 ; $i<$a ; $i++ ){
    fscanf(STDIN, '%s', $word);
    $b =strlen($word);
    if ($b >= 10) {
        echo $word[0].($b-2).$word[strlen($word)-1] , "\n";
    }
    else{echo $word ,"\n";}
}

<?php fscanf ( STDIN, '%d', $num1 ); while ( fscanf ( STDIN, '%s', $var1) ) { $num = strlen ( $var1 ); if ($num > 10) { 	$var1 = $var1[0] . ($num-2) . $var1[$num-1]; } echo $var1;} ?>

<?php

$data = array();
$data = file('php://stdin');

if($data[0] >= 1 && $data[0] <= 100){
    $amount = array_shift($data);
}

$dataClear = array();
foreach($data as $k){
    if(strlen(trim($k)) < 10){
        $dataClear[] = trim($k);
    }
    if(strlen(trim($k)) > 10){
        $lenght = (strlen(trim($k)) -2);
        $lChar = strtolower(substr(trim($k), 0, 1));
        $rChar = strtolower(substr(trim($k), -1));
        $dataClear[] = $lChar.$lenght.$rChar;
    }

}
$counter;
if($amount < count($dataClear)){
    $counter = $amount;
}else{
    $counter = count($dataClear);
}
for($i = 0; $i < $counter ; $i++){
  echo($dataClear[$i])."\n";
}

?>

<?php

// php://input or input.txt or STDIN
$input = STDIN;

// php://output or output.txt or STDOUT
$output = STDOUT;

define('MAX_LENGTH', 10);

function foo($s)
{
    $sl = strlen($s);

    if ($sl > MAX_LENGTH) {
        return $s[0] . ($sl - 2) . $s[$sl - 1];
    }

    return $s;
}

$n = trim(fgets($input, 3));

for ($i = 0; $i < $n; $i++) {
    $s = trim(fgets($input, 101));

    $r = foo($s);

    if ($i + 1 < $n) {
        $r .= PHP_EOL;
    }

    echo ltrim($r);
}

<?
$n=fgets(STDIN);
for($i=0;$i<$n;$i++)
    {
        $nam = fgets(STDIN);
        $ln = strlen($nam);
        if($ln>10){
            echo substr($nam,0,1);
            echo ($ln)-2;
            echo substr($nam,-1);
          }
         else echo $nam;
    }
?>


Marian is at a casino. The game at the casino works like this.Before each round, the player selects a number between $$$1$$$ and $$$10^9$$$. After that, a dice with $$$10^9$$$ faces is rolled so that a random number between $$$1$$$ and $$$10^9$$$ appears. If the player guesses the number correctly their total money is doubled, else their total money is halved. Marian predicted the future and knows all the numbers $$$x_1, x_2, \dots, x_n$$$ that the dice will show in the next $$$n$$$ rounds. He will pick three integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$l \leq r$$$). He will play $$$r-l+1$$$ rounds (rounds between $$$l$$$ and $$$r$$$ inclusive). In each of these rounds, he will guess the same number $$$a$$$. At the start (before the round $$$l$$$) he has $$$1$$$ dollar.Marian asks you to determine the integers $$$a$$$, $$$l$$$ and $$$r$$$ ($$$1 \leq a \leq 10^9$$$, $$$1 \leq l \leq r \leq n$$$) such that he makes the most money at the end.Note that during halving and multiplying there is no rounding and there are no precision errors. So, for example during a game, Marian could have money equal to $$$\dfrac{1}{1024}$$$, $$$\dfrac{1}{128}$$$, $$$\dfrac{1}{2}$$$, $$$1$$$, $$$2$$$, $$$4$$$, etc. (any value of $$$2^t$$$, where $$$t$$$ is an integer of any sign).

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot 10^5$$$) — the number of rounds. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \leq x_i \leq 10^9$$$), where $$$x_i$$$ is the number that will fall on the dice in the $$$i$$$-th round. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, output three integers $$$a$$$, $$$l$$$, and $$$r$$$ such that Marian makes the most amount of money gambling with his strategy. If there are multiple answers, you may output any of them.

NoteFor the first test case, the best choice is $$$a=4$$$, $$$l=1$$$, $$$r=5$$$, and the game would go as follows.   Marian starts with one dollar.  After the first round, he ends up with $$$2$$$ dollars because the numbers coincide with the chosen one.  After the second round, he ends up with $$$4$$$ dollars because the numbers coincide again.  After the third round, he ends up with $$$2$$$ dollars because he guesses $$$4$$$ even though $$$3$$$ is the correct choice.  After the fourth round, he ends up with $$$4$$$ dollars again.  In the final round, he ends up $$$8$$$ dollars because he again guessed correctly. There are many possible answers for the second test case, but it can be proven that Marian will not end up with more than $$$2$$$ dollars, so any choice with $$$l = r$$$ with the appropriate $$$a$$$ is acceptable.

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = fscanf(STDIN, str_repeat('%d ', $n));// array_filter();

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 200003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 200003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 100003;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $sources = $ar;
    foreach($ar as &$el) {
        $el %= 100003;
    }
    unset($el);
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        //100003
        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];
    $maxIt = $sources[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
//
//    if ($n === 12500 && $t === 12) {
//        var_dump($totalRead, $totalPrepare, $totalLoop);
//        die;
//    }
}
//        var_dump($totalRead, $totalPrepare, $totalLoop);

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $sourceArr = array_filter(fscanf(STDIN, $format));

    $ar = [];
    foreach ($sourceArr as $key => $el) {
        // if el is power of 2, source array lookup will give us a hard time
        $ar[] = $el % 10007;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $sourceArr[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}

/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = [];

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        if (!isset($latestPosition[$it])) {
            $latestPosition[$it] = $currentPos;
            continue;
        }

        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);

    if ($n === 12500 && $t === 12) {
        var_dump($totalRead, $totalPrepare, $totalLoop);
        die;
    }
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

$totalRead = 0;
$totalPrepare = 0;
$totalLoop = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;

    $maxP = 1;
    $maxR = 0;

    $beforePrepare = microtime(true);

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    $afterPrepare = microtime(true);
    $totalPrepare += $afterPrepare - $beforePrepare;

    $beforeLoop = microtime(true);

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $afterLoop = microtime(true);
    $totalLoop += $afterLoop - $beforeLoop;

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);

    if ($n === 12500 && $t === 12) {
        var_dump($totalRead, $totalPrepare, $totalLoop);
        die;
    }
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

$totalRead = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    $totalRead += $afterRead - $beforeRead;
    if ($n === 12500 && $t === 11) {
        var_dump($afterRead - $beforeRead, $totalRead, $afterRead - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

$totalRead = 0;

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $afterRead = microtime(true);

    if ($n === 12500 && $t === 10) {
        var_dump($afterRead - $beforeRead, $totalRead, $afterRead - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

$format = str_repeat('%d ', 2 * 10 ** 5);

fscanf(STDIN, '%d', $t);

$start = microtime(true);

while ($t--) {
    fscanf(STDIN, '%d', $n);

    $beforeRead = microtime(true);
    $ar = array_filter(fscanf(STDIN, $format));
    $now = microtime(true);

    if ($n === 12500 && $t === 10) {
        var_dump($now - $beforeRead, $now - $start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%d', $t);

$ns = [];

while ($t--) {
    fscanf(STDIN, '%d', $n);
    $ns[] = $n;
    if ($n === 12500 && $t === 15) {
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n === 12500 && $t === 10) {
        $end = microtime(true);
        var_dump($end - $start, $ns);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500 && $t === 15){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500&& $t === 10) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500 && $t === 15){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500&& $t === 12) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%d', $t);

while ($t--) {
    fscanf(STDIN, '%d', $n);
    if ($n===12500){
        $start = microtime(true);
    }
    $ar = fscanf(STDIN, str_repeat('%d ', $n));

    if ($n===12500) {
        $end = microtime(true);
        var_dump($end-$start);
        die;
    }

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;
    }

    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%d %d %d'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%u', $t);
$startTime = microtime(true);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;

        if ((microtime(true) - $startTime) > 0.2) {
            die(500);
            break;
        }
    }

    sleep(1);

    fprintf(STDOUT, '%d', (microtime(true) - $startTime) * 100);

    die;
    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

fscanf(STDIN, '%u', $t);
$startTime = microtime(true);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    $maxP = 1;
    $maxR = 0;

    $dm = array_fill(0, $n, 1);
    $dmStarts = array_keys($dm);
    $latestPosition = array_flip(array_reverse($ar, true));

    foreach ($ar as $currentPos => $it) {
        $prevPos = $latestPosition[$it];
        $gap = $currentPos - $prevPos - 1;

        if (!~$gap) {
            continue;
        }

        $powerWithGap = 1 + $dm[$prevPos] - $gap;

        if ($powerWithGap > 1) {
            $dm[$currentPos] = $powerWithGap;
            $dmStarts[$currentPos] = $start = $dmStarts[$prevPos];

            if ($maxP < $powerWithGap) {
                $maxP = $powerWithGap;
                $maxR = $currentPos;
            }
        }

        $latestPosition[$it] = $currentPos;

        if ((microtime(true) - $startTime) > 0.2) {
            die(500);
            break;
        }
    }

    fprintf(STDOUT, '%d', microtime(true) * 1000);

    die;
    $maxL = $dmStarts[$maxR];
    $maxIt = $ar[$maxL];

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1
// 1 1 1

1
5
1 2 2 3 4
// 2 2 3

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3
// 3 3 3
 */

<?php

phpinfo();
die;

fscanf(STDIN, '%u', $t);

while ($t--) {
    fscanf(STDIN, '%u', $n);
    $ar = fscanf(STDIN, str_repeat('%u ', $n));

    /** @var array<int, array<int, int>> $pos */
    $pos = array_fill_keys($ar, []);

    foreach ($ar as $key => $it) {
        $pos[$it][] = $key;
    }

    $maxP = 1;
    $maxL = 0;
    $maxR = 0;
    $maxIt = $ar[0];

    foreach ($pos as $it => $occ) {
        $mI = count($occ);

        if ($maxP >= $mI) {
            continue;
        }

        // matrix, holding optimal powers if start from the index
        $dm = array_fill(0, $mI, 1);// array_fill_keys ($occ, 1);
        $dmStarts = array_keys($dm);

        $prevPos = $occ[0];
        foreach ($occ as $i => $currentPos) {
            $gap = $currentPos - $prevPos - 1;

            if (~$gap) {
                $powerWithGap = 1 + $dm[$i - 1] - $gap;

                if ($powerWithGap > 1) {
                    $dm[$i] = $powerWithGap;
                    $dmStarts[$i] = $start = $dmStarts[$i - 1];

                    if ($maxP < $powerWithGap) {
                        $maxP = $powerWithGap;
                        $maxL = $occ[$start];
                        $maxR = $currentPos;
                        $maxIt = $it;
                    }
                }
            }

            $prevPos = $currentPos;
        }
    }

    fprintf(STDOUT, '%u %u %u'.PHP_EOL, $maxIt, $maxL + 1, $maxR + 1);
}
/*

We would check every number and:
- each idex will have weight

1
1
1

1
5
1 2 2 3 4

1
6
1 2 2 3 2 2
// 2 2 6

1
6
2 2 3 2 2 1
// 2 1 5

1
3
1 2 3

 */


Monocarp has been collecting rare magazines for quite a while, and now he has decided to sell them. He distributed the magazines between $$$n$$$ boxes, arranged in a row. The $$$i$$$-th box contains $$$a_i$$$ magazines. Some of the boxes are covered with lids, others are not. Suddenly it started to rain, and now Monocarp has to save as many magazines from the rain as possible. To do this, he can move the lids between boxes as follows: if the $$$i$$$-th box was covered with a lid initially, he can either move the lid from the $$$i$$$-th box to the box $$$(i-1)$$$ (if it exists), or keep the lid on the $$$i$$$-th box. You may assume that Monocarp can move the lids instantly at the same moment, and no lid can be moved more than once. If a box will be covered with a lid after Monocarp moves the lids, the magazines in it will be safe from the rain; otherwise they will soak.You have to calculate the maximum number of magazines Monocarp can save from the rain.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of the testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of boxes. The second line contains a string of $$$n$$$ characters 0 and/or 1. If the $$$i$$$-th character is 1, the $$$i$$$-th box is initially covered with a lid. If the $$$i$$$-th character is 0, the $$$i$$$-th box is initially not covered. The third line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^4$$$), where $$$a_i$$$ is the number of magazines in the $$$i$$$-th box. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print one integer — the maximum number of magazines Monocarp can save from the rain.

NoteIn the first testcase of the example, Monocarp can move the lid from the second box to the first box, so the boxes $$$1$$$, $$$3$$$ and $$$4$$$ are covered, and $$$10 + 8 + 9 = 27$$$ magazines are saved.In the second testcase, Monocarp can move the lid from the second box to the first box, then from the third box to the second box, then from the fifth box to the fourth box, and then from the sixth box to the fifth box. The boxes $$$1$$$, $$$2$$$, $$$4$$$ and $$$5$$$ will be covered, so $$$20 + 10 + 30 + 20 = 80$$$ magazines can be saved.There are no lids in the third testcase, so it's impossible to save even a single magazine.

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $s = IO::get();
   $a = IO::getArray();
   $temp = str_split($s);
   $ans =0;
   $j = -1;
   for ($i = 0; $i < $n; $i++) {
        if ($temp[$i] == '0') {
            $j = $i;
        } else if ($j >= 0 && $a[$i] < $a[$j]) {
             $t = $temp[$i];
            $temp[$i] = $temp[$j];
            $temp[$j] = $t;
            $j = $i;
        }
    }

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

         if( $temp[$i] == 1) {
              $ans += $a[$i];
         }

    }

    IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $s = IO::get();
   $a = IO::getArray();
   $ans =0;
   $max = 0;
   $tt = [];
   $temp = str_split($s);
   $f = 0;
   $ind = 0;
    for($i=0; $i<$n; $i++) {
     //    IO::pr($ind . ' ' . $a[$i]  . ' ' . $max);
         if($f == 0) {
             $aMax[] =  $a[$i];
             $max =  0;
         } else {
              $max = $a[$i];
              for($j = $ind; $j < $i; $j++) {
                   if($temp[$j] == 0 && $max < $a[$j]) {
                        $ind = $j;
                        $max = $a[$j];
                        $temp[$i] = 0;
                   }
              }
              if($s[$i] == 1) {
                  $temp[$ind] = 1;
              }
               $aMax[] = $max;
         }

        if($temp[$i] == 0 ) {
             $f++;
        }
    }
//    IO::pr($ind);
//    IO::prArray($temp);
//  IO::prArray($aMax);

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

         if( $s[$i] == 1) {
              $ans += $aMax[$i];
         }

    }

    IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $s = IO::get();
   $a = IO::getArray();
   $ans =0;
   $max = 0;
   $tt = [];
   $temp = str_split($s);
   $f = 0;
   $ind = 0;
    for($i=0; $i<$n; $i++) {
     //    IO::pr($ind . ' ' . $a[$i]  . ' ' . $max);
         if($f == 0) {
             $aMax[] =  $a[$i];
             $max =  0;
         } else {
              $max = $a[$i];
              for($j = $ind; $j < $i; $j++) {
                   if($temp[$j] == 0 && $max < $a[$j]) {
                        $ind = $j+1;
                        $max = $a[$j];
                        $temp[$i] = 0;
                   }
              }
               $aMax[] = $max;
         }

        if($temp[$i] == 0 ) {
             $f++;
        }
    }
//    IO::pr($ind);
//    IO::prArray($temp);
//  IO::prArray($aMax);

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

         if( $s[$i] == 1) {
              $ans += $aMax[$i];
         }

    }

    IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}


There is a robot in a warehouse and $$$n$$$ packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point $$$(0, 0)$$$. The $$$i$$$-th package is at the point $$$(x_i, y_i)$$$. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package.The robot is semi-broken and only can move up ('U') and right ('R'). In other words, in one move the robot can go from the point $$$(x, y)$$$ to the point ($$$x + 1, y$$$) or to the point $$$(x, y + 1)$$$.As we say above, the robot wants to collect all $$$n$$$ packages (in arbitrary order). He wants to do it with the minimum possible number of moves. If there are several possible traversals, the robot wants to choose the lexicographically smallest path.The string $$$s$$$ of length $$$n$$$ is lexicographically less than the string $$$t$$$ of length $$$n$$$ if there is some index $$$1 \le j \le n$$$ that for all $$$i$$$ from $$$1$$$ to $$$j-1$$$ $$$s_i = t_i$$$ and $$$s_j < t_j$$$. It is the standard comparison of string, like in a dictionary. Most programming languages compare strings in this way.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then test cases follow. The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of packages. The next $$$n$$$ lines contain descriptions of packages. The $$$i$$$-th package is given as two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \le x_i, y_i \le 1000$$$) — the $$$x$$$-coordinate of the package and the $$$y$$$-coordinate of the package. It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point $$$(0, 0)$$$ doesn't contain a package. The sum of all values $$$n$$$ over test cases in the test doesn't exceed $$$1000$$$.

Print the answer for each test case. If it is impossible to collect all $$$n$$$ packages in some order starting from ($$$0,0$$$), print "NO" on the first line. Otherwise, print "YES" in the first line. Then print the shortest path — a string consisting of characters 'R' and 'U'. Among all such paths choose the lexicographically smallest path. Note that in this problem "YES" and "NO" can be only uppercase words, i.e. "Yes", "no" and "YeS" are not acceptable.

NoteFor the first test case in the example the optimal path RUUURRRRUU is shown below:

<?php
$i = trim(fgets(STDIN));

for($j = 0; $j < $i; $j++){
    $k = trim(fgets(STDIN));
    $a = array();
    for($m = 0; $m < $k; $m++){
        $d = explode(" ", trim(fgets(STDIN)));
        $a[$d[0]][] = $d[1];
    }
    ksort($a);
    $x = 0;
    $y = 0;
    $res = '';
    foreach($a as $key => $val){
        sort($val);
        if($key >= $x){
            for($t = 0; $t < $key - $x; $t++){
                    $res .= 'R';
                }
            $x = $key;
        } else {
            echo "NO\n";
            continue 2;
        }
        foreach($val as $v){
            if($v >= $y){
                for($t = 0; $t < $v - $y; $t++){
                    $res .= 'U';
                }
                $y = $v;
            } else {
                echo "NO\n";
                continue 3;
            }
        }

    }
    echo "YES\n";
    echo $res."\n";

}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
function cmp($a, $b)
{
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}
for($j=0;$j<$t;$j++)
{
    $n = trim(fgets($handle));
    $arr=[];
    for($i=0;$i<$n;$i++)
    {
        $a=trim(fgets($handle));
        $a=explode(" ",$a);

        $arr[]=[$a[0],$a[1]];
    }
    usort($arr,'cmp');
    $str='';$check=true;
    $lastx=0;$lasty=0;
    foreach ($arr as $k=>$v)
    {
        if($v[0]<$lastx || $v[1]<$lasty)
        {$check=false;break;}
        for($l=$lastx;$l<$v[0];$l++)
        {
            $str=$str."R";
        }
        for($l=$lasty;$l<$v[1];$l++)
        {
            $str=$str."U";
        }
        $lastx=$v[0];
        $lasty=$v[1];
    }
    if($check)
    {
        echo "YES"."\n";
        echo $str."\n";

    }else {
       echo "NO"."\n";
    }

}

?>


You are given two strings of equal length $$$s$$$ and $$$t$$$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.For example, if $$$s$$$ is "acbc" you can get the following strings in one operation:   "aabc" (if you perform $$$s_2 = s_1$$$);  "ccbc" (if you perform $$$s_1 = s_2$$$);  "accc" (if you perform $$$s_3 = s_2$$$ or $$$s_3 = s_4$$$);  "abbc" (if you perform $$$s_2 = s_3$$$);  "acbb" (if you perform $$$s_4 = s_3$$$); Note that you can also apply this operation to the string $$$t$$$.Please determine whether it is possible to transform $$$s$$$ into $$$t$$$, applying the operation above any number of times.Note that you have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is represented by two consecutive lines. The first line of each query contains the string $$$s$$$ ($$$1 \le |s| \le 100$$$) consisting of lowercase Latin letters. The second line of each query contains the string $$$t$$$ ($$$1 \le |t| \leq 100$$$, $$$|t| = |s|$$$) consisting of lowercase Latin letters.

For each query, print "YES" if it is possible to make $$$s$$$ equal to $$$t$$$, and "NO" otherwise. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive answer).

NoteIn the first query, you can perform two operations $$$s_1 = s_2$$$ (after it $$$s$$$ turns into "aabb") and $$$t_4 = t_3$$$ (after it $$$t$$$ turns into "aabb"). In the second query, the strings are equal initially, so the answer is "YES".In the third query, you can not make strings $$$s$$$ and $$$t$$$ equal. Therefore, the answer is "NO".

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     $d = array_intersect($b, $c);
     if(count($d) == 0)
     {
          print "NO\n";
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
$str1=trim(fgets(STDIN));
$str2=trim(fgets(STDIN));
$flag=0;
for ($i=0; $i <strlen($str1) ; $i++)
{
	for ($j=0; $j <strlen($str1) ; $j++)
	{
       if($str1[$i]==$str2[$j])
       	   {
       	   	$flag=1;
       	   	echo "YES\n";
       	   	break;
       	   }
	}
	if($flag==1)
		break;
}
if($flag==0)
echo "NO\n";
}


A revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island.The island can be conventionally represented as two rectangles a × b and c × d unit squares in size correspondingly. The rectangles are located close to each other. At that, one of the sides with the length of a and one of the sides with the length of c lie on one line. You can see this in more details on the picture.  The i-th party is entitled to a part of the island equal to xi unit squares. Every such part should fully cover several squares of the island (it is not allowed to cover the squares partially) and be a connected figure. A "connected figure" presupposes that from any square of this party one can move to any other square of the same party moving through edge-adjacent squares also belonging to that party.Your task is to divide the island between parties.

The first line contains 5 space-separated integers — a, b, c, d and n (1 ≤ a, b, c, d ≤ 50, b ≠ d, 1 ≤ n ≤ 26). The second line contains n space-separated numbers. The i-th of them is equal to number xi (1 ≤ xi ≤ a × b + c × d). It is guaranteed that .

If dividing the island between parties in the required manner is impossible, print "NO" (without the quotes). Otherwise, print "YES" (also without the quotes) and, starting from the next line, print max(b, d) lines each containing a + c characters. To mark what square should belong to what party, use lowercase Latin letters. For the party that is first in order in the input data, use "a", for the second one use "b" and so on. Use "." for the squares that belong to the sea. The first symbol of the second line of the output data should correspond to the square that belongs to the rectangle a × b. The last symbol of the second line should correspond to the square that belongs to the rectangle c × d. If there are several solutions output any.


You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 300$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i, j}$$$ is the number written in the $$$j$$$-th cell of the $$$i$$$-th row ($$$0 \le a_{i, j} \le 10^9$$$). It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.

If it is impossible to obtain a good grid, print a single line containing "NO". Otherwise, print a single line containing "YES", followed by $$$n$$$ lines each containing $$$m$$$ integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero). If there are multiple possible answers, you may print any of them.

NoteIn the first test case, we can obtain the resulting grid by increasing the number in row $$$2$$$, column $$$3$$$ once. Both of the cells that contain $$$1$$$ have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid $$$$$$0\;1\;0\;0$$$$$$ $$$$$$0\;2\;1\;0$$$$$$ $$$$$$0\;0\;0\;0$$$$$$ All of them are accepted as valid answers.In the second test case, it is impossible to make the grid good.In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.