<?php

/*
 * http://codeforces.com/contest/1515
 */

// $file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");

$rowsNumber = trim(fgets($file));

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $x) = explode(" ", trim(fgets($file)));
    $pieces      = explode(" ", trim(fgets($file)));

    $n = (int) $n;
    $x = (int) $x;

    if (array_sum($pieces) < $x) {
        echo "YES" . PHP_EOL;
        echo implode(" ", $pieces);
        echo PHP_EOL;

        continue;
    }

    if (array_sum($pieces) === $x) {
        echo "NO" . PHP_EOL;

        continue;
    }

    $sum = 0;
    for ($j=0; $j<count($pieces)-1; $j++) {
        $sum += $pieces[$j];

        if ($sum === $x) {
            $buffer       = $pieces[$j];
            $pieces[$j]   = $pieces[$j+1];
            $pieces[$j+1] = $buffer;
        }
    }

    echo "YES" . PHP_EOL;
    echo implode(" ", $pieces);
    echo PHP_EOL;
}

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($n, $x) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));

  rsort($a);
  $sum = array_sum($a);

  if ($sum == $x) { echo 'NO'.PHP_EOL; }

  if ($sum < $x) {
    echo 'YES'.PHP_EOL;
    for ($j = 0; $j < $n; $j++) {
      echo $a[$j].' ';
    }
    echo PHP_EOL;
  }

  if ($sum > $x) {
    $m = 0;
    for ($j = 0; $j < $n; $j++) { $m += $a[$j]; $r[$j] = $m; }

    $c = array_search($x, $r);
    if ($c === false) {
      $f = 1;
    } else {
      $d = $n + 1;
      while ($d--) {
        $m = $a[$n - 1];
        unset($a[$n - 1]);
        array_unshift($a, $m);

        $r = array();
        $m = 0;

        for ($j = 0; $j < $n; $j++) { $m += $a[$j]; $r[$j] = $m; }

        $c = array_search($x, $r);
        if ($c === false) { $f = 1; break; }
        $g++;
      }
    }

    if ($f == 1) {
      echo 'YES'.PHP_EOL;
      for ($j = 0; $j < $n; $j++) { echo $a[$j].' '; }
      echo PHP_EOL;
    } else { echo 'NO'.PHP_EOL; }
}

}

?>

<?php

/*
 * http://codeforces.com/contest/1515
 */

// $file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");

$rowsNumber = trim(fgets($file));

for ($i=0; $i<$rowsNumber; $i++) {
    list($n, $x) = explode(" ", trim(fgets($file)));
    $pieces      = explode(" ", trim(fgets($file)));

    $n = (int) $n;
    $x = (int) $x;

    if (array_sum($pieces) < $x) {
        echo "YES" . PHP_EOL;
        echo implode(" ", $pieces);
        echo PHP_EOL;

        return;
    }

    if (array_sum($pieces) === $x) {
        echo "NO" . PHP_EOL;

        return;
    }

    $sum = 0;
    for ($j=0; $j<count($pieces)-1; $j++) {
        $sum += $pieces[$j];

        if ($sum === $x) {
            $buffer       = $pieces[$j];
            $pieces[$j]   = $pieces[$j+1];
            $pieces[$j+1] = $buffer;
        }
    }

    echo "YES" . PHP_EOL;
    echo implode(" ", $pieces);
    echo PHP_EOL;
}