<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $flag = [false, false];
    for ($i = 1; $i <= 8; $i++) {
        $s = trim(fgets(STDIN));
        if (empty($flag[0])) {
            $flag[0] = (2 == count_chars($s, 1)[35]);
        } elseif (empty($flag[1])) {
            $flag[1] = (1 == count_chars($s, 1)[35]);
        }
        if ($flag[1]) {
            printf("%d %d\n", $i, (strpos($s, '#')+1));
            break;
        }
    }
    while (++$i <= 8) fgets(STDIN);
}

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

 $loop = true;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
       $xA = 0;
       $yA = 0;
      $a = [];
      $tt = [];
      $empty = IO::getInt();
      for($i = 0; $i<8; $i++) {
           $ss = IO::getInt();
           $a[] = $ss;

      }
      for($i = 0; $i<8; $i++) {
           for($j=0; $j<8; $j++) {
               if($a[$i][$j] == '#') {
                    $tt[$i][] = $j;
               }
           }

           if(count($tt[$i]) == 2) {
                if($tt[$i][1] - $tt[$i][0] == 2) {
                     $yA = $tt[$i][1];
                     $xA = $i+2;
                    //  IO::pr("break " . $i);
                    //  IO::prArray($tt[$i]);
                     break;
                }
           }
      }
     IO::pr($xA . " " . $yA);

   $a = [];
      $tt = [];
 }

 class IO {
      public static function getInt()
      {
          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;
     }
 }

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
     public static function efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $spa = trim(fgets(STDIN));
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];
    print_r($r1 . "\n");
    print_r($r2 . "\n");
    print_r($r3 . "\n");
    print_r($r4 . "\n");
    print_r($r5 . "\n");
    print_r($r6 . "\n");
    print_r($r7 . "\n");
    print_r($r8 . "\n");
    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];
    print_r($arr);
    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;

    for ($i = 1; $i < count($arr) - 1; $i++) {

        if ($mk != 0) {
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }
    $nn = array_search($x, $arr, true) + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $nn = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $nn++;
        if ($mk != 0) {
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }

    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $nn = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if ($mk != 0) {
            $nn = $i;
            break;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
            }
        }
    }

    $pos = strpos($x, "#") + 1;
    $fin = $nn . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if ($mk == 0) {
            $n++;
        }
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;

            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
                $n ++;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $mk = 0;
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1 and $mk == 0) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $mk++;
                $n = $i;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 1;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        $n++;
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];

                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>

<?php

$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }
    $fin_n = $n + 1;
    $pos = strpos($x, "#") + 1;
    $fin = $fin_n . ' ' . $pos + 1;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $r1 = trim(fgets(STDIN));
    $r2 = trim(fgets(STDIN));
    $r3 = trim(fgets(STDIN));
    $r4 = trim(fgets(STDIN));
    $r5 = trim(fgets(STDIN));
    $r6 = trim(fgets(STDIN));
    $r7 = trim(fgets(STDIN));
    $r8 = trim(fgets(STDIN));
    $arr = [$r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8];

    $x = "";
    $n = 0;
    for ($i = 1; $i < count($arr) - 1; $i++) {
        if (substr_count($arr[$i], '#') == 1) {
            if (substr_count($arr[$i - 1], '#') == 2 and substr_count($arr[$i + 1], '#') == 2) {
                $x = $arr[$i];
                $n = $i;
                break;
            }
        }
    }

    $pos = strpos($x, "#");
    $fin = $n + 1 . ' ' . $pos + 1;
    array_push($array, $fin);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();

?>


<?php
    $n = trim(fgets(STDIN));
    $sum_peo = 0;
    $sum_cap = 0;
    $a = array();
    for($i=0;$i<$n;$i++){
        $arr = explode(" ", trim(fgets(STDIN)));
        //print_r($arr);
        if($arr[0] == '+'){
            $sum_peo ++;
            $a[] = $arr[1];
            if($sum_cap < $sum_peo){
                $sum_cap = $sum_peo;
            }
        }else{
            if(in_array($arr[1], $a)){
                $sum_peo --;
            }else{
                $sum_cap ++;
            }
        }
    }
    echo $sum_cap."\n";


<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i < $m; $i++) {
    $b = false;
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 1; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
        if(isset($x[$a[$j]]) && isset($x[-$a[$j]])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
$b = false;
for($i = 0; $i < $m; $i++) {
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 0; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
    }
    for($j = 1; $j <= $n; $j++) {
        if(isset($x[$j]) && isset($x[-$j])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";

<?php
list($n, $m) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i < $m; $i++) {
    $b = false;
    $x = array();
    $a = explode(' ', trim(fgets(STDIN)));
    for($j = 0; $j < count($a); $j++) {
        $x[$a[$j]] = 1;
        if(isset($x[$a[$j]]) && isset($x[-$a[$j]])) {
            $b = true;
        }
    }
    if(!$b) {
        echo "YES";
        exit;
    }
}
echo "NO";


<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$chars=[];

for ($k = 0; $k < $t; $k++) {
    for ($i='a';$i<'z';$i++)
    {
        $chars[$i]=0;
    }
    $chars['z']=0;
    $h=trim(fgets($handle));
    $h=explode(' ',$h);
    $n=$h[0];$m=$h[1];
    $str=trim(fgets($handle));
    $arr=trim(fgets($handle));
    $arr=explode(' ',$arr);

    for ($i=0;$i<$n;$i++)
    {
        $chars[$str[$i]]+=1;
    }
    $new=[];$count=0;
    for($i=0;$i<$m;$i++)
    {
        if(isset($new[$arr[$i]]))
        $new[$arr[$i]]+=1;
        else
            $new[$arr[$i]]=1;

        $count++;
    }
    for ($i=0;$i<$n;$i++)
    {
        $chars[$str[$i]]+=$count;
        if(isset($new[$i+1]))
        {
            $count-=$new[$i+1];
            $new[$i+1]=0;
        }
    }
    foreach ($chars as $b=>$v)
    {
        echo $v." ";
    }
    echo "\n";
}


<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 193 Div 2 (Unofficial Participant) Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130720 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORT FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
$str = g(1);

$ct = 0;
for ($i = $n; $i < strlen($str); $i += $n) {
	if ((substr($str, $i-3, 1) == substr($str, $i-2, 1)) && (substr($str, $i-3, 1) == substr($str, $i-1, 1))) {$ct++;}
}
echo $ct;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    // $max_beer = (2000/$mod)-1;

    // if($beer_count > $max_beer)
    //     $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
        echo $participant_size%$mod;
    }

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    // if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
    // }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    if($beer_count>499)
        $beer_count=499;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($split_text[1], $participant_size-9,20));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($participant_size%$mod == 0 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $max_beer -= 1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3] && $beer_count!=0)
        $beer_count -= 1;

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(range($participant_size-9, $participant_size-1));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = $participant_size/$mod;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $max_beer -= 1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count > $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    // if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
    // }
    echo $participant_size%$mod;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
        $beer_count -= 1;

    echo $beer_count;

<?php
	$input = "4
abbba";
    // $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0')-1;
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i%$mod];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else
    		$valid_flag=0;

    	if($i%$mod == ($mod-1) && $valid_flag==1)
    		$beer_count++;
    	$prev_sign=$string[$i%$mod];
    }
    echo $beer_count;

<?php
// 	$input = "4
// abbaabbba";
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');
    // var_dump($mod);
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else{
    		if($i%$mod != 1){
    			$valid_flag=0;
    			while(($i%$mod) != $mod-1)
    				$i++;
    		}
    	}

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}

    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count > $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 0 && $string[$participant_size-2] == $string[$participant_size-3] && $string[$participant_size-3] == $string[$participant_size-1] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
    //     var_dump($participant_size);
    //     var_dump(substr($split_text[1], $participant_size-9,20));
        echo $participant_size%$mod;
    }

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;
    if($beer_count==398){
        var_dump($participant_size);
        var_dump(range($participant_size-9, $participant_size-1));
    }
    // echo $beer_count;

<?php
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0')-1;
    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);

    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		continue;
    	}

    	$curr_sign=$string[$i%$mod];

    	if($curr_sign==$prev_sign)
    		$valid_flag=1;
    	else
    		$valid_flag=0;

    	if($i%$mod == ($mod-1) && $valid_flag==1)
    		$beer_count++;
    	$prev_sign=$string[$i%$mod];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    // if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size-3])
    //     $max_beer -= 1;

    if($beer_count == 398){
        var_dump($participant_size);
        var_dump($string);
    }

    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    if($participant_size>2000)
        $participant_size=2000;
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    if($participant_size/$mod>500)
        $participant_size=500*$mod;
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = ($participant_size/$mod)-1;
    if($beer_count> $max_beer)
        $beer_count=$max_beer;
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == 1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($split_text[1], $participant_size-9,20));
    }
    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    echo $beer_count;

<?php
/*	$input = "4
abbab";*/
    $input = trim(file_get_contents("php://stdin"));
    $split_text = explode("\n",$input);
    $mod = ($split_text[0]-'0');

    $participant_size = strlen($split_text[1]);
    $beer_count=0;
    $prev_sign="";
    $curr_sign="";
    $string = str_split($split_text[1]);
    // var_dump($participant_size);
    for($i=0; $i<$participant_size;$i++){
    	if($i%$mod==0){
    		$prev_sign="";
    		$valid_flag=0;
    		while(($i%$mod) < ($mod-3) && $i<$participant_size-1)
    			$i++;
    	}
		$curr_sign=$string[$i];
        if($i%$mod>$mod-3){
        	if($curr_sign==$prev_sign)
        		$valid_flag=1;
        	else{
        			$valid_flag=0;
        			while(($i%$mod) != $mod-1 && $i<$participant_size-1)
        				$i++;
        	}
        }

    	if(($i%$mod)==$mod-1 && $valid_flag==1){
    		$beer_count++;
    	}
    	$prev_sign=$string[$i];
    }
    $max_beer = (2000/$mod)-1;

    if($beer_count> $max_beer)
        $beer_count=$max_beer;

    if($participant_size%$mod == $mod-1 && $string[$participant_size-1] == $string[$participant_size-2] && $string[$participant_size-2] == $string[$participant_size] && $beer_count!=0)
        $beer_count -= 1;

    if($beer_count==398){
        var_dump($participant_size);
        var_dump(substr($string, $participant_size-9,20));
    }
    echo $beer_count;


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     for($y = 0; $y < $b; $y++)
     {
          if($c[$y] > 2048)
          {
               unset($c[$y]);
          }
     }
     $d = array_sum($c);
     if($d < 2048)
     {
          print "NO\n";
     }
     else
     {
          print "YES\n";
     }
}
?>

<?php

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

function solve() {
    global $__fp;
    $n = fgets($__fp);
    $s = array_map('intval', explode(' ', fgets($__fp)));
    $sum = 0;
    foreach ($s as $p) {
        if ($p == 2048) {
            echo 'YES'. PHP_EOL;
            return;
        } else if ($p < 2048) {
            $sum += $p;
        }
    }
    if ($sum >= 2048) {
        echo 'YES' . PHP_EOL;
    } else {
        echo 'NO' . PHP_EOL;
    }
    return;
}

$q = fgets($__fp);
for ($i = 0; $i < $q; $i++) {
    solve();
}

<?php
$q = (int)fgets(STDIN);
while ($q--) {
    $n = (int)fgets(STDIN);
    $a = array_map(function ($x) { return (int)$x; }, explode(' ', trim(fgets(STDIN))));
    $cnt = array();
    foreach ($a as $i)
        $cnt[$i] ++;

    for ($i = 1; $i < 2048; $i *= 2) {
        if (!array_key_exists($i, $cnt)) continue;
        $cnt[$i * 2] += (int)($cnt[$i] / 2);
    }
    if (array_key_exists(2048, $cnt) && $cnt[2048] > 0) printf("YES\n");
    else printf("NO\n");
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
        ksort($arr_);
    }
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
    }
//    var_dump($arr_);
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
    }
    unset($arr_, $v, $c);
//    var_dump($arr_);
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}

<?php
#1221A
$k = (int)fgets(STDIN);
while ($k--) {
    $n = (int)fgets(STDIN);
    $arr = explode(' ', trim(fgets(STDIN)));
    $arr_ = [];
    foreach ($arr as $v) {
        if (!isset($arr_[$v])) {
            $arr_[$v] = 1;
        } else {
            $arr_[$v]++;
        }
    }
    if (isset($arr_[2048])) {
        echo 'YES' . PHP_EOL;
        continue;
    }
    ksort($arr_);
    foreach ($arr_ as $v => &$c) {
        while ($c > 1) {
            @$arr_[$v * 2]++;
            $c -= 2;
        }
        unset($v, $c);
    }
    echo (isset($arr_[2048]) ? 'YES' : 'NO') . PHP_EOL;
}


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = floor($b / 2);
     $e = array_reverse(array_slice($c, 0, $d));
     $f = array_reverse(array_slice($c, $d));
     $g = array_merge($f, $e);
     print implode(" ", $g) . "\n";
}
?>


<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = 0;
     while(TRUE)
     {
          if($b == 1)
          {
               print $c . "\n";
               break;
          }
          else
          {
               if(bcmod($b, 2) == 0)
               {
                    $b = bcdiv($b, 2);
                    $c++;
               }
               elseif(bcmod(bcmul($b, 2), 3) == 0)
               {
                    $b = bcdiv(bcmul($b, 2), 3);
                    $c++;
               }
               elseif(bcmod(bcmul($b, 4), 5) == 0)
               {
                    $b = bcdiv(bcmul($b, 4), 5);
                    $c++;
               }
               else
               {
                    print "-1\n";
                    break;
               }
          }
     }
}
?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}
$c = 0;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = array_pop($unusedNumbers);
        $c++;
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = array_pop($unusedNumbers);
        $c++;
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}

for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = array_pop($unusedNumbers);
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = array_pop($unusedNumbers);
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();

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

    if ($eArray[$i]>$itemsNumber || isset($usedNumbers[$eArray[$i]])) {
        $eArray[$i] = 0;

    }else{
        $usedNumbers[$eArray[$i]] = 1;
    }
}
$c = 1;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i] == 0) {
        while (isset($usedNumbers[$c])) {
            $c++;
        }
        $usedNumbers[$c] = 1;
        $eArray[$i] = $c;
    }
}
echo implode(" ", $eArray);

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$itemsNumber = trim(fgets($file));
$eArray = explode(" ", trim(fgets($file)));
$usedNumbers = array();
$unusedNumbers = array();
for ($i=0; $i<$itemsNumber; $i++) {
    if (isset($usedNumbers[$eArray[$i]])) {
        $usedNumbers[$eArray[$i]]++;
    } else {
        $usedNumbers[$eArray[$i]] = 1;
    }
}
for ($i = 1; $i<=$itemsNumber; $i++) {
    if (!isset($usedNumbers[$i])) {
        $unusedNumbers[] = $i;
    }
}
$c = 0;
for ($i=0; $i<$itemsNumber; $i++) {
    if ($eArray[$i]>$itemsNumber) {
        $eArray[$i] = $unusedNumbers[$c];
        $c++;
    } elseif ($usedNumbers[$eArray[$i]] > 1) {
        $usedNumbers[$eArray[$i]]--;
        $eArray[$i] = $unusedNumbers[$c];
        $c++;
    }
}
echo implode(" ", $eArray);


<?php
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

$sc = new Scanner();
$t = $sc->nextInt();
for($j = 0; $j < $t; $j++)
{
    $n = $sc->nextInt();
    $s = $sc->nextInt();
    $a = array();
    $sum = 0;
    $index = 0;
    $max = 0;
    $b = false;
    for($i = 0; $i < $n; $i++)
    {
        $a[$i] = $sc->nextInt();
        if($b) continue;
        $sum += $a[$i];
        //out::println($sum);
        if($max < $a[$i])
        {
            $max = $a[$i];
            $index = $i;
        }
        if($s < $sum)
        {
            $b = true;
           // break;
        }
    }
    if($b)
    {
        out::println($index + 1);
    }
    else
    {
        out::println("0");
    }
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for($j=0;$j<$t;$j++)
{
    $n=trim(fgets($handle));
    $n=explode(' ',$n);
    $arr=trim(fgets($handle));
    $arr=explode(' ',$arr);
    $id=0;$ans=$n[1];
        for($i=0;$i<$n[0];$i++) {
            if($arr[$i]>$arr[$id])
            {
                $id=$i;
            }
            $ans-=$arr[$i];

            if($ans<0)break;
        }
    if($ans>=0)
    {
        $id=-1;
    }
    echo ($id+1)."\n";
}

?>


<?php
class INPUT_HELP{
    public function read_array(){
        $a[0] = '';
        $j = 0;
        $input = fgets(STDIN);
        for ($i = 0; $i < strlen($input); $i++){
            if (preg_replace("/[0-9A-zА-я._-]/",null,$input[$i]) == false) {
                $a[$j] = $a[$j].$input[$i];
            } else {
                if ($a[$j] != '') {
                    ++$j;
                    $a[$j] = '';
                }
            }
        }
        return $a;
    }
    public function read_one(){
        $array = $this->read_array();
        return $array[0];
    }
}
?>
<?php
    $input_connect = new INPUT_HELP();
    $a = $input_connect->read_array();
    $n = $a[0];
    $k = $a[1];
    $t = $a[2];
    $sum = floor(($n * $k * $t) / 100);
    for ($i = 0; $i < $n; $i++){
        if ($sum == 0) echo '0 ';
        if ($sum < $k && $sum > 0) {
            echo $sum.' ';
            $sum = 0;
        };
        if ($sum >= $k) {
            echo $k.' ';
            $sum -= $k;
        }
    }
?>

<?php
fscanf(STDIN,'%d %d %d', $n, $k, $t);
$all=$n*$k;
$completed=floor($all*$t/100);
for($i=0;$i<$n;$i++){
    if($completed>0){
        $j=min($k,$completed);
        $completed-=$j;
        echo $j." ";
    } else echo "0 ";
}
?>


<?php
$fl =STDIN;
fscanf($fl, "%d\n", $n);
$numbers = explode(" ", trim(fgets($fl)));
$length=0;
$currentLength = 0;
$current = -1;
$zebra = true;
for($i=0;$i<$n;++$i)
{
    $a = $numbers[$i];

    if ($current === -1) {
        $current = $a;
    }

    if ($a === $current) {
        $currentLength += 1;
    } else {
        $current = $a;

        if ($length === 0) {
            $length = $currentLength;

        } else if ($length !== $currentLength) {
            $zebra = false;
            break;
        }

        $currentLength = 1;
    }
}

if ($length !== $currentLength && $length !== 0) {
    $zebra = false;
}

if ($zebra === true) {
    printf("YES");
} else {
    printf("NO");
}

?>

<?php

$fl =STDIN;

$prev = 2;
$line = -1;
$cur = 0;
$ans = 0;
list($n) = explode(" ", trim(fgets(STDIN)));
$arr = explode(" ", trim(fgets(STDIN)));
for($i=1;$i<=$n;++$i)
{
	$a = $arr[$i-1];
    #printf("%d\n", $a);
	if ($i == 1) {
	    $cur = 1;
	} else {
	    if ($a == $prev) {
	        $cur = $cur + 1;
	    } else {
	        if ($line == -1) {
	            $line = $cur;
	            $cur = 1;

	        } else {
	            if ($line == $cur) {
	                $cur = 1;
	            } else {
	                $ans = 1;
	            }
	        }
	    }
	}
    $prev = $a;
	#printf("%d %d\n", $ans, $cur);
}
if ($line == -1) {
	            $line = $cur;
	            $cur = 1;

	        } else {
	            if ($line == $cur) {
	                $cur = 1;
	            } else {
	                $ans = 1;
	            }
	        }
#printf("%d %d\n", $ans, $cur);
if ($ans == 0)
		printf("%s\n",'YES');
	else
		printf("%s\n",'NO');
?>

<?php
    fscanf(STDIN, "%d\n", $n); // читает число из STDIN
    $line = trim(fgets(STDIN)); // читает одну строку из STDIN
    $x = 1;
    $tmp1 = $line[0];
    $color = $tmp1;
    $cnt = 1;
    $cnt_prev = -1;
    while ($x != $n)
    {
        $tmp = $line[2 * $x];
        if ($tmp == $color)
        {
            $cnt++;
        }
        else
        {
            if ($cnt_prev != -1)
            {
                if ($cnt != $cnt_prev)
                {
                    echo "NO";
                    return;
                }
                else
                {
                    $cnt_prev = $cnt;
                    $cnt = 1;
                    $color = $tmp;
                }
            }
            else
            {
              $cnt_prev = $cnt;
              $cnt = 1;
              $color = $tmp;
            }
        }
        $x++;
    }
    if ($cnt_prev == $cnt or $cnt_prev == -1)
    {
        echo "YES";
    }
    else {
        echo "NO";
    }
?>

<?php

$fl =STDIN;
fscanf($fl, "%d\n", $n);
$last = -1;
$last_color = -1;
$size = 0;
$last_size = 0;
$ok = 0;
$input = explode(' ', trim(fgets($fl)));
for($i=0;$i<$n;++$i){
	if($last == -1){
	    $last = $input[$i];
	    $size = 1;
	} else {
	    if($last == $input[$i]) $size = $size + 1;
	    else{
	        if($last_color == -1){

	        } else {
	            if($size == $last_size);
	            else{
	                ++$ok;
	            }
	        }
	        $last_color = $last;
	        $last_size = $size;
	        $last = $input[$i];
	        $size = 1;
	    }
	}
}
    if($last_color == -1){

	        } else {
	            if($size == $last_size);
	            else{
	                ++$ok;
	            }
	        }
	 if($ok == 0) printf("YES\n");
	 else printf("NO\n");
?>

<?php
function in(){
	return trim(fgets(STDIN));
}
function inarr(){
	return explode(' ', in());
}

$n = in();
$a = inarr();
$cur = $a[0];
$count = 0;
$period = -1;
$flag = 0;

for($i=0; $i<$n; $i++){
    //print $a[$i];
	if($a[$i]!=$cur){
		if($period!=-1 && $count!=$period){
			$flag=1; break;
		}

		$period = $count;
		$cur = $a[$i];
		$count = 1;
	}
	else{
		$count++;
	}
}
if($period!=-1 && $count!=$period){
	$flag=1;
}

if($flag==0){
	print "YES";
}
else{
	print "NO";
}

<?php
$fl =STDIN;//fopen("input.txt","r");
$flag = TRUE;
$prev = -1;
$count = -1;
$prevcount = -1;

$segments = explode(" ", trim(fgets(STDIN)) );
$n = trim($segments[0]);
//$segments = explode(" ", fgets(STDIN) );

$arr = explode(" ", trim(fgets(STDIN)) );
for($i=0;$i<$n;++$i)
{
	$a = $arr[$i];
    //echo $a;
	if ($a == $prev) {
	    $count++;
	} else {
	    if ($prevcount != -1) {
	        //echo $prevcount;

	        if ($count != $prevcount) {
	            $flag = FALSE;

	        }
	    }

	    $prevcount = $count;
	    $count = 1;
	}
	$prev = $a;
}

if ($prevcount != -1) {
     if ($count != $prevcount) $flag = FALSE;
}

if ($flag == TRUE) {
echo "YES";
} else {
echo "NO";

}

<?php

    // go to this idea
    // go to php
    // go to me
    // go to you
    // go to mellicard
    // go to johnny

    $n = fgets(STDIN);
    $cnt = 1; $mn = $n; $mx = 0;
    $s; $tmp; $last;
    $s = fgets(STDIN);
    $last = $s[0];

    for($i = 2 ; $i < strlen($s) ; $i = $i + 2){

        if($i < 2*$n){
            $tmp = $s[$i];

            if($tmp == $last)
                $cnt++;
            else{
                if($cnt > $mx)
                    $mx = $cnt;
                if($cnt < $mn)
                    $mn = $cnt;

                $cnt = 1;
                $last = $tmp;
            }
        }
    }

    if($cnt > $mx)
        $mx = $cnt;
    if($cnt < $mn)
        $mn = $cnt;

    if($mn == $mx)
        echo "YES";
    else
        echo "NO";

?>

<?php
	$n = (int)fgets(STDIN);
    $arr = explode(" ", trim(fgets(STDIN)));
	$siz = -1;
	$currsiz = 1;
	$good = 1;
	$i = 1;
	$prev = $arr[0];
	while ($i < $n) {
		$curr = $arr[$i];
		if($curr == $prev) {
		    $currsiz++;
		} else {
		    if($siz == -1) {
		        $siz = $currsiz;
		    } else {
		        if($siz != $currsiz) {
		            $good = 0;
		        }
		    }
		    $currsiz = 1;
		    $prev = $curr;
		}
		$i++;
	}
    if($siz == -1) {
        $siz = $currsiz;
    } else {
        if($siz != $currsiz) {
            $good = 0;
        }
    }
	if($good == 1) {
	    echo("YES");
	} else {
	    echo("NO");
	}
?>

<?php

$n=(int)fgets(STDIN);
$a=fgets(STDIN);

$fa=-1;
$nowa=0;
for($i=0;$i<$n;++$i)
{
	if($a[$i] == $olda){
		++$nowa;
	}else{
		$olda=$a[$i];
		if($fa == -1){
			$fa=$nowa;
		}elseif($fa == -2){

		}else{
			if($fa==$nowa)
				$nowa=1;
			else $fa=-2;

		}

	}
}
if($fa==-2){
	printf("NO");
}else{
	printf("YES");
}

?>

<?php
	$n = (int)fgets(STDIN)-1;
	$prev = (int)fgets(STDIN);
	$siz = -1;
	$currsiz = 1;
	$good = 1;
	while ($n >= 0) {
		$curr = (int)fgets(STDIN);
		if($curr == $prev) {
		    $currsiz++;
		} else {
		    if($siz == -1) {
		        $siz = $currsiz;
		    } else {
		        if($siz != $currsiz) {
		            $good = 0;
		        }
		    }
		    $siz = 1;
		    $prev = $curr;
		}
		$n--;
	}
    if($siz == -1) {
        $siz = $currsiz;
    } else {
        if($siz != $currsiz) {
            $good = 0;
        }
    }
	if($good == 1) {
	    echo("YES");
	} else {
	    echo("NO");
	}
?>


<?php
fscanf(STDIN,"%d",$t);
while($t--)
{
        fscanf(STDIN,"%d",$n);
        $arr=explode(' ',trim(fgets(STDIN)));
		//$cnt=0;
		//$newArr=array();
		$pos=array();
		for ($i=0,$j=0; $i <$n; $i++)
		{
			if($arr[$i]==1)
				{
					$pos[$j]=$i;
					//$newArr[$j]=$arr[$i];
					$j++;
				}

		}
		//print_r($pos);
		if(count($pos)==1)
			echo "0\n";
		else
		    {   $cnt=0;
		    	$firstPos=$pos[0];
		    	$lstindx=count($pos)-1;
		    	$lstPos=$pos[$lstindx];
		    	for ($i=$firstPos;$i <=$lstPos ; $i++)
		    	{
		    		if($arr[$i]==0)
		    			$cnt++;
		    	}
		    	echo "$cnt\n";

		    }

}

<?php
    $jt = trim(fgets(STDIN));
    for($sr = 0; $sr < $jt; $sr++){
        $i = trim(fgets(STDIN));
        $a = explode(" ", trim(fgets(STDIN)));
        $ic = 0;
        $ie = 0;
        $b = false;
        foreach($a as $c){
            if($c == 1){
                $b = true;
                $ie = 0;
            }
            if($b && $c == 0){
                $ic++;
                $ie++;
            }
        }
        echo $ic - $ie. "\n";

    }

?>


<?php

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

//
//    $input = '3
//2 987
//3 654
//1 321';

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();

    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    $totalWidth = 0;
    $maxHeight = 0;
    $heightArray = array();
    foreach ($dimensionsOfFriends as $key => $value) {
        $width = (int)$value[0];
        $height = (int)$value[1];
        $heightArray[] = $height;

        $totalWidth += $width;
        if ($height > $maxHeight) {
            $maxHeight = $height;
        }
    }

    $photoSize = $totalWidth * $maxHeight;

    arsort($heightArray);
    $maxHeight1 = array_shift($heightArray);
    $maxHeight2 = array_shift($heightArray);

    $photoSizeArray = array();
    for ($i = 0; $i<$nrFriends; $i++){
        if ((int)$dimensionsOfFriends[$i][1] == $maxHeight1 && $maxHeight2 != $maxHeight1){
            $photoSizeArray[] = ($totalWidth - (int)$dimensionsOfFriends[$i][0]) * ($maxHeight2);
        } else {
            $photoSizeArray[] = ($photoSize - (int)$dimensionsOfFriends[$i][0]*$maxHeight1);
        }

    }

    echo implode(' ', $photoSizeArray);

<?php
$n = trim(fgets(STDIN));
$arr_width = $arr_height = array();
for ($i = 0; $i<$n; $i++) {
list($arr_width[$i],$arr_height[$i])= explode(" ",trim(fgets(STDIN)));
}
$sum = array_sum($arr_width);
arsort($arr_height);
for ($i = 0; $i<$n; $i++) {
if (key($arr_height) == $i) {
next($arr_height);
printf("%d ",($sum-$arr_width[$i])*current($arr_height));
prev($arr_height);
} else {
printf("%d ",($sum-$arr_width[$i])*current($arr_height));
}
}
?>

<?php
$n = trim(fgets(STDIN));
$arr = $h = array();
for ($i = 0; $i<$n; $i++) {
list($arr[$i],$h[$i])= explode(" ",trim(fgets(STDIN)));
}
$sum = array_sum($arr);
arsort($h);
for ($i = 0; $i<$n; $i++) {
if (key($h) == $i) {
next($h);
printf("%d ",($sum-$arr[$i])*current($h));
prev($h);
} else {
printf("%d ",($sum-$arr[$i])*current($h));
}
}
?>

<?php
$s = fopen("php://stdin", 'r');
$input = explode("\n",stream_get_contents($s));
unset($s);
$w = 0;
$h = array();
for($i=1;$i<=$input[0];$i++) {
    $line = explode(' ',$input[$i]);
    $w += $line[0];
    $h[$i] = (int) $line[1];
}
arsort($h);
for($i=1;$i<=$input[0];$i++) {
    $line = explode(' ',$input[$i]);

    if(key($h) == $i && reset($h) == (int) $line[1]) {
        list($max) = array_slice($h, 1, 1);
    } elseif((int) $line[1] > reset($h)) {
        $max = (int) $line[1];
    } else {
        $max = (int) reset($h);
    }
    echo (($w - (int) $line[0]) * $max)." ";
}
?>

<?php
$n = fgets(STDIN);
$totalWidth = 0;
for($i = 0; $i < $n; ++$i){
    $t = explode(' ', fgets(STDIN));
    $widths[] = (int)$t[0];
    $heights[] = (int)$t[1];
    $totalWidth += (int)$t[0];
}
$maxHeight = max($heights);
$maxCount = 0;
for($i = 0; $i < $n; ++$i){
    if($heights[$i] == $maxHeight)
        ++$maxCount;
}

for($i = 0; $i < $n; ++$i){
    $width = $totalWidth - $widths[$i];
    if($maxCount > 1 || $heights[$i] < $maxHeight){
        $height = $maxHeight;
    }else{
        $t = $heights[$i];
        $heights[$i] = 0;
        $height = max($heights);
        $heights[$i] = $t;
    }
    echo ($height * $width).' ';
}
?>

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

$n = trim(fgets($fileIN));

$w = array();
$h = array();

$wsum = 0;

for ($i = 0; $i < $n; $i++) {
    $line = explode(" ", trim(fgets($fileIN)));
    $w[$i] = $line[0];
    $h[$i] = $line[1];
    $wsum += $w[$i];
}

$max1 = 0;
$max2 = 0;
$max1pos = 0;

for ($i = 0; $i < $n; $i++) {
    if ($h[$i] > $max1) {
        $max1 = $h[$i];
        $max1pos = $i;
    }
}

for ($i = 0; $i < $n; $i++) {
    if (($h[$i] > $max2) && ($i != $max1pos)) {
        $max2 = $h[$i];
    }
}

for ($i = 0; $i < $n; $i++) {
    $wtot = $wsum - $w[$i];
    $htot = 0;
    if ($h[$i] == $max1) {
        $htot = $max2;
    } else {
        $htot = $max1;
    }
    fprintf($fileOUT, $wtot * $htot . " ");
}

fclose($fileIN);
fclose($fileOUT);
?>

<?php
$w = array();
$w_sum = 0;
$h_max = 0;
$h_max_index = 0;
$h_pre_max = 0;
$count = (int) fgets(STDIN);
for ($i = 0; $i < $count; $i++) {
    list($user_w, $user_h) = explode(" ", fgets(STDIN));
    $w[] = (int) $user_w;
	$w_sum += (int) $user_w;
	$user_h = (int) $user_h;
	if ($h_max < $user_h) {
		$h_pre_max = $h_max;
		$h_max = $user_h;
		$h_max_index = $i;
	} elseif ($h_pre_max < $user_h) {
		$h_pre_max = $user_h;
	}
}
for ($i = 0; $i < $count; $i++) {
	$group_w = $w_sum - $w[$i];
	if ($i == $h_max_index) $group_h = $h_pre_max;
	else $group_h = $h_max;
	echo ($group_w * $group_h) . " ";
}
?>

<?php
$fCount=fgets(STDIN);
$friends=array();
$totalwidth=0;
$maxH=array(array("id"=>0,"h"=>0),array("id"=>0,"h"=>0));
for($i=0;$i<$fCount;$i++)
{
    list($w,$h)=explode(" ",strtolower(fgets(STDIN)));
	$h=trim($h);
	$w=trim($w);
    $friends[$i]=array("w"=>$w,"h"=>$h);
	if($maxH[0]["h"]<$h)
	{
		$maxH[1]=$maxH[0];
		$maxH[0]=array("id"=>$i,"h"=>$h);
	}
	elseif($maxH[1]["h"]<$h)
	{
		$maxH[1]=array("id"=>$i,"h"=>$h);
	}
	$totalwidth+=$w;
}
$sizes=array();
foreach($friends as $i=>$value)
{
	$H=(($maxH[0]["id"]==$i)?$maxH[1]["h"]:$maxH[0]["h"]);
    $sizes[]=($totalwidth-$value["w"])*$H;
}
echo implode(" ",$sizes);
?>

<?php
$fd = fopen("php://stdin", 'r');
$friendsCount = trim(fgets($fd));

$widths  = [];
$maxHeight = 0;
$prevMaxHeight = 0;
$maxHeightPointer = 0;
$sumWidth = 0;
$pointer = 1;

while (!feof($fd)) {
    list($width, $height) = explode(" ", trim(fgets($fd)));
    if (!$width || !$height) break;

    $widths[$pointer] = $width;
    $sumWidth += $width;

    if ($height >= $maxHeight) {
        $prevMaxHeight = $maxHeight;
        $maxHeight = $height;
        $maxHeightPointer = $pointer;
    } elseif ($height >= $prevMaxHeight) {
        $prevMaxHeight = $height;
    }
    $pointer++;
}

$f = false;
foreach ($widths as $key => $width) {
    $height = $key == $maxHeightPointer ? $prevMaxHeight : $maxHeight;
    $square = ($sumWidth - $width) * $height;
    echo ($f ? " " : "") . $square;
    $f = true;
}

<?php
$n = trim(fgets(STDIN));
$w = $h = $h_cur = array();
for ($i = 0; $i<$n; $i++) {
    list($w[$i],$h[$i])= explode(" ",trim(fgets(STDIN)));
}
$sum = array_sum($w);
$max = max($h);
$next_max = 0;
$max_counter = 0;
for ($i = 0; $i<$n; $i++) {
    if ($h[$i]==$max) $max_counter++;
    if ($max_counter>=2){
        $next_max = $max;
        break;
    }
    if ($next_max < $h[$i] && $h[$i] < $max)
        $next_max = $h[$i];
}
for ($i = 0; $i<$n; $i++) {
    printf("%d ",($sum-$w[$i])*(($max==$h[$i])?$next_max:$max));
}
?>

<?php
$fd = fopen("php://stdin", 'r');
$friendsCount = trim(fgets($fd));

$widths  = [];
$heights = [];
$maxHeight = 0;
$sumWidth = 0;

while (!feof($fd)) {
    list($width, $height) = explode(" ", trim(fgets($fd)));
    foreach ($widths as $key => $value) {
        $widths[$key] += $width;
        $heights[$key] = max($heights[$key], $height);
    }
    $widths[] = $sumWidth;
    $heights[] = $maxHeight;
    $sumWidth += $width;
    $maxHeight = max($maxHeight, $height);
}

$squares = [];
foreach (array_keys($widths) as $key) {
    $squares[$key] = $widths[$key] * $heights[$key];
}
echo implode(" ", $squares);

<?php
fscanf(STDIN,"%d",$n);
function c($wd,$hd,$k){
	unset($wd[$k]);
	unset($hd[$k]);
	return array_sum($wd)*max($hd);
}
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%d %d",$w[],$h[]);
}
fclose($fp);
for ($j=0; $j < $n; $j++) {
	echo c($w,$h,$j)."<br>";
}
?>

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends == 200000) {
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        $output = array_fill(1, $nrFriends, $size);

        return implode(' ', $output);

    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($inputArray as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends == 200000) {
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        $output = array_fill(1, $nrFriends, $size);

        echo implode(' ', $output);
        exit();
    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($dimensionsOfFriends as $key => $value) {
            $width = (int)$value[0];
            $height = (int)$value[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends == 200000) {
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        return implode(' ', array_fill(1, $nrFriends, $size));

    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($inputArray as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

<?php

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();

    $maxHeight1 = array(0, 0);
    $maxHeight2 = array(0, 0);
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
        if ($dimensionsOfFriends[$key][1] > $maxHeight1[1]) {
            $maxHeight1 = array($key, $dimensionsOfFriends[$key][1]);
        }
        if ($dimensionsOfFriends[$key][1] > $maxHeight2[1] && $key != $maxHeight1[0]) {
            $maxHeight2 = array($key, $dimensionsOfFriends[$key][1]);
        }

    }

    $totalWidth = 0;
    $maxHeight = 0;
    foreach ($dimensionsOfFriends as $key => $value) {
        $width = (int)$value[0];
        $height = (int)$value[1];

        $totalWidth += $width;
        if ($height > $maxHeight) {
            $maxHeight = $height;
        }
    }

    $photoSize = $totalWidth * $maxHeight;

    $photoSizeArray = array();
    for ($i = 0; $i<$nrFriends; $i++){
        if ((int)$dimensionsOfFriends[$i][1] == $maxHeight1[1] && $maxHeight2[1] != $maxHeight1[1]){
            $photoSizeArray[] = ($totalWidth - (int)$dimensionsOfFriends[$i][0]) * ($maxHeight2[1]);
        } else {
            $photoSizeArray[] = ($photoSize - (int)$dimensionsOfFriends[$i][0]*$maxHeight1[1]);
        }

    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends == 200000) {
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        $output = array_fill(1, $nrFriends, $size);

        echo implode(' ', $output);
        exit();
    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($dimensionsOfFriends as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode('\n', $input);

    $nrFriends = $inputArray[0];

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    $photoSizeArray = array();
    for ($i = 0; $i <= $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($dimensionsOfFriends as $key => $value) {
            if ($key != $i) {
                $totalWidth += $value[0];
                if ($value[1] > $maxHeight) {
                    $maxHeight = $value[1];
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends>5000){
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        return implode(' ', array_fill(1, $nrFriends, $size));

    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($inputArray as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if ($nrFriends = 200000) {
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        return implode(' ', array_fill(1, $nrFriends, $size));

    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($inputArray as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
    }

    if (count(array_unique($dimensionsOfFriends)) == 1){
        $width = (int)$dimensionsOfFriends[0][0];
        $height = (int)$dimensionsOfFriends[0][1];
        $size = $width * ($nrFriends - 1) * $height;

        return implode(' ', array_fill(0, $nrFriends, $size));

    }

    $photoSizeArray = array();
    for ($i = 0; $i < $nrFriends; $i++) {
        $totalWidth = 0;
        $maxHeight = 0;
        foreach ($inputArray as $key => $value) {
            $dimensions = explode(' ', $value);
            $width = (int)$dimensions[0];
            $height = (int)$dimensions[1];

            if ($key != $i) {
                $totalWidth += $width;
                if ($height > $maxHeight) {
                    $maxHeight = $height;
                }
            }
        }

        $photoSizeArray[$i] = $totalWidth * $maxHeight;
    }

    echo implode(' ', $photoSizeArray);

<?php

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

    $inputArray = explode(PHP_EOL, $input);

    $nrFriends = (int)array_shift($inputArray);

    $dimensionsOfFriends = array();

    $maxHeight1 = array(0, 0);
    $maxHeight2 = array(0, 0);
    foreach ($inputArray as $key => $value) {
        $dimensionsOfFriends[$key] = explode(' ', $value);
        if ($dimensionsOfFriends[$key][1] > $maxHeight1[1]) {
            $maxHeight1 = array($key, $dimensionsOfFriends[$key][1]);
        }
        if ($dimensionsOfFriends[$key][1] > $maxHeight2[1] && $key != $maxHeight1[0]) {
            $maxHeight2 = array($key, $dimensionsOfFriends[$key][1]);
        }

    }

    $totalWidth = 0;
    $maxHeight = 0;
    foreach ($dimensionsOfFriends as $key => $value) {
        $width = (int)$value[0];
        $height = (int)$value[1];

        $totalWidth += $width;
        if ($height > $maxHeight) {
            $maxHeight = $height;
        }
    }

    $photoSize = $totalWidth * $maxHeight;

    $photoSizeArray = array();
    for ($i = 1; $i<=$nrFriends; $i++){
        if ((int)$dimensionsOfFriends[$i][1] == $maxHeight1[1] && $maxHeight2[1] != $maxHeight1[1]){
            $photoSizeArray[] = ($totalWidth - (int)$dimensionsOfFriends[$i][0]) * ($maxHeight2[1]);
        } else {
            $photoSizeArray[] = ($photoSize - (int)$dimensionsOfFriends[$i][0]*(int)$dimensionsOfFriends[$i][1]);
        }

    }

    echo implode(' ', $photoSizeArray);

<?php
$s = fopen("php://stdin", 'r');
$input = explode("\n",stream_get_contents($s));
$px = array();
for($i=1;$i<=$input[0];$i++) {
	$wsum = 0;
	$maxh = 0;
	for($k=1;$k<=$input[0];$k++) {
		if($k != $i) {
			$line = explode(" ",$input[$k]);
			if($line[1] > $maxh)
				$maxh = $line[1];
			$wsum += $line[0];
		}
	}
	$px[$i] = $wsum * $maxh;
}
echo implode(" ",$px);
?>


<?php

$n = trim(fgets(STDIN));

$a = explode(' ', trim(fgets(STDIN)));

$h = $n-1;
$l = 0;

while ($a[$h] == $a[0]) $h--;
while ($a[$l] == $a[$n-1]) $l++;

fwrite(STDOUT, max($n-1-$l, $h));

?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_reverse($b);
$b = array_unique($b);
$c = array_unique($c);
$d = array_keys($b);
$e = array_keys($c);
$f = max($d[count($d) - 1] - $d[0], $e[count($e) - 1] - $e[0]);
print $f;
?>


<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%d",$len);
	$line=explode(' ',trim(fgets(STDIN)));
	$ara=array();
	foreach ($line as $value)
	{
		if(array_key_exists($value, $ara))
			$ara[$value]++;
		else
			$ara[$value]=1;
	}
	$min=1000000000;
	$flag=0;
	foreach ($ara as $key=>$value)
	{
		if($value==1)
		 {
		 	$flag=1;
		 	if($key<$min)
		 		$min=$key;
		 }
	}
	if($flag==0)
		echo "-1\n";
	else
	{
	  echo implode(array_keys($line,$min))+1;
	  echo "\n";
	}

}

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

while ($t--) {
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $a1 = preg_split("/[\s,]+/", $s);
    $ex = [];
    $aResults = [];
    $aResults2 = [];
    for ($i = 0; $i < $n; $i++) {
        if (isset($ex[$a1[$i]])) {
            unset($aResults[$a1[$i]]);
            unset($aResults2[$a1[$i]]);
        } else {
            $aResults[$a1[$i]] = $i+1;
            $aResults2[$a1[$i]] = $a1[$i];
            $ex[$a1[$i]] = 1;
        }
    }

    echo $aResults ? $aResults[min($aResults2)] : -1;
    echo "\n";
}

<?php

function solve() {
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $a1 = preg_split("/[\s,]+/", $s);
    $aResults = []; $iMin = -1;
    for ($i = 0; $i < $n; $i++) {
        if (isset($aResults[$a1[$i]])) {
            $aResults[$a1[$i]][] = $i + 1;
        } else {
            $aResults[$a1[$i]] = [$i + 1];
        }
    }

    foreach ($aResults as $iValue => $aV) {
        if (count($aV) == 1) {
            if ($iMin == -1) {
                $iMin = $iValue;
            } elseif ($iValue < $iMin) {
                $iMin = $iValue;
            }
        }

    }

    return $iMin == -1 ? $iMin : current($aResults[$iMin]);
}

$t = trim(fgets(STDIN));
while ($t--) {
    echo solve();
    echo "\n";
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $arr = explode(' ', trim(fgets(STDIN)));
    $result = false;
    $cnt = array_intersect(array_count_values($arr), [1])
    and ksort($cnt)
    and reset($cnt);
    printf("%d\n", $cnt ? key(array_intersect($arr, [key($cnt)])) + 1 : -1);
}


<?php
list($n, $k) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$id = array_map('intval', explode(' ', trim(fgets(STDIN))));
$m = 0;
$idpos = $mpos = [];
for ($i = 0; $i < $n; $i++) {
    if ((!isset($idpos[$id[$i]])) || ($m - $idpos[$id[$i]] >= $k)) {
        $m++;
        $idpos[$id[$i]] = $m;
        $mpos[$m] = $id[$i];
    }
}
echo min($m, $k) . PHP_EOL;
for ($i = $m; $i > max($m - $k, 0); $i--) {
    echo $mpos[$i] . ' ';
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = array();
for($x = 0; $x < $a; $x++)
{
     if(count($d) < $b)
     {
          if($e[$c[$x]] == FALSE)
          {
               array_unshift($d, $c[$x]);
               $e[$c[$x]] = TRUE;
          }
     }
     else
     {
          if($e[$c[$x]] == FALSE)
          {
               $e[$d[count($d) - 1]] = FALSE;
               $e[$c[$x]] = TRUE;
               unset($d[count($d) - 1]);
               array_unshift($d, $c[$x]);
          }
     }
}
print count($d) . "\n";
print implode(" ", $d);
?>

<?php
list($n, $k) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$aTest = [];
$aTest[] = $aArray[0];
$j = 0;
foreach ($aArray as $sK => $sV){
    if(!in_array($sV,$aTest) && $k > count($aTest)){
        $aTest[] = $sV;
    } elseif(!in_array($sV,$aTest) && $k <= count($aTest)) {
        $aTest[$j] = 'a';
        $aTest[] = $sV;
        $j++;
    }
}
$aAnswer = [];
for($i = $j; $i < count($aTest); $i++){
    $aAnswer[] = $aTest[$i];
}
echo count($aAnswer) . "\n";
echo implode(" ",array_reverse($aAnswer));

<?php
list($n, $k) = array_map('intval', explode(' ', trim(fgets(STDIN))));
$id = array_map('intval', explode(' ', trim(fgets(STDIN))));
$m = 0;
$idpos = $mpos = [];
for ($i = 0; $i < $n; $i++) {
    if ((!isset($idpos[$id[$i]])) || ($m - $idpos[$id[$i]] >= $k)) {
        $m++;
        $idpos[$id[$i]] = $m;
        $mpos[$m] = $id[$i];
    }
}
$x = min($m, $k) . PHP_EOL;
for ($i = $m; $i > $m - min($m, $k); $i--) {
    $x .= $mpos[$i] . ' ';
}
echo $x;

<?php
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));
$res = [];
foreach($b as $v){
     if(isset($res[$v])){
            continue;
    } else {
        if(count($res) < $a[1]){
            $res[$v] = 1;
        } else {
            //array_shift($res);
            foreach($res as $sK => $aV){
                unset($res[$sK]);
                break;
            }
            $res[$v] = 1;
        }
    }
}
echo count($res)."\n";
foreach(array_reverse($res, true) as $k => $v){
    echo $k.' ';
}


<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

$answer = "YES";

fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
	fscanf(STDIN, "%d %d", $a, $b);
	if (!isset($cur)) {
		$cur = max($a, $b);
	} else {
		$mmax = max($a, $b);
		$mmin = min($a, $b);

		if ($mmax <= $cur) {
			$cur = $mmax;
		} else if ($mmin <= $cur) {
			$cur = $mmin;
		} else {
			$answer = "NO";
		}
	}
}

echo $answer;

<?php
$a = trim(fgets(STDIN));
if($a == 1)
{
     print "YES";
}
else
{
     $b = 0;
     list($c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = max($c, $d);
     for($x = 1; $x < $a; $x++)
     {
          list($c, $d) = explode(" ", trim(fgets(STDIN)));
          if(($c <= $e) && ($d <= $e))
          {
               $e = max($c, $d);
          }
          elseif($c <= $e)
          {
               $e = $c;
          }
          elseif($d <= $e)
          {
               $e = $d;
          }
          else
          {
               $b = 1;
               break;
          }
     }
     if($b == 0)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>