#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, d;
    cin >> n >> d;
    long long kd[n + 5];
    long long hlt = (n * (n - 1)) / 2;
    long long llt = 0;
    long long depth[n + 5];
    memset(depth, 0, sizeof(depth));
    kd[1] = 0;
    depth[0]++;
    for (long long i = 2; i <= n; i++) {
      kd[i] = kd[i / 2] + 1;
      llt += kd[i];
      depth[kd[i]]++;
    }
    if (d < llt or d > hlt) {
      cout << "NO" << '\n';
      continue;
    }
    long long diff = d - llt;
    long long h = n - 1;
    while (depth[h] == 0) {
      h--;
    }
    long long pm = h++;
    while (diff > 0) {
      long long pmi;
      while (depth[pm] == 1) {
        pm--;
      }
      pmi = pm;
      while (pmi < h && diff > 0) {
        depth[pmi]--;
        depth[pmi + 1]++;
        pmi++;
        diff--;
      }
      if (pmi == h) {
        h++;
      }
    }
    cout << "YES" << '\n';
    long long x = 0, y = 1;
    for (long long i = 1; i < n; i++) {
      for (long long j = 0; j < depth[i]; j++) {
        cout << (x + j / 2 + 1) << " ";
      }
      x = y;
      y += depth[i];
    }
    cout << '\n';
  }
  return 0;
}
