#include <bits/stdc++.h>
using namespace std;
template <typename T>
void ckMin(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void ckMax(T& a, T b) {
  a = max(a, b);
}
int amt[5000];
int n, d;
bool solve() {
  cin >> n >> d;
  int currSize = n * (n - 1) / 2;
  memset(amt, 0, sizeof(amt));
  for (auto(i) = (0); (i) < (n); ++(i)) amt[i] = 1;
  if (currSize == d) return true;
  for (auto(currD) = (n - 1); (currD) >= (0); --(currD)) {
    while (amt[currD]) {
      amt[currD]--;
      int lowest = currD;
      for (auto(i) = (currD - 1); (i) >= (1); --(i)) {
        if (amt[i] < 2 * amt[i - 1]) {
          lowest = i;
          if (currSize - (currD - i) == d) {
            amt[i]++;
            return true;
          }
        }
      }
      if (lowest == currD) return false;
      currSize -= currD - lowest;
      amt[lowest]++;
    }
  }
  return false;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int tc;
  cin >> tc;
  while (tc--) {
    if (solve()) {
      cout << "YES\n";
      int cntTotal = 1;
      for (auto(i) = (1); (i) < (n); ++(i)) {
        for (auto(j) = (0); (j) < (amt[i]); ++(j))
          cout << 1 + cntTotal - amt[i - 1] + j / 2 << ' ';
        cntTotal += amt[i];
      }
      cout << '\n';
    } else {
      cout << "NO\n";
    }
  }
}
