#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    int ub = n * (n - 1) / 2;
    int lb = 0;
    int cur = 0;
    for (int i = 1; i <= n; ++i) {
      if (!(i & (i - 1))) {
        cur++;
      }
      lb += cur - 1;
    }
    if (d < lb || d > ub) {
      puts("NO");
      continue;
    }
    vector<int> par(n);
    iota(par.begin(), par.end(), -1);
    vector<int> n_ch(n, 1);
    n_ch[n - 1] = 0;
    vector<int> depth(n);
    iota(depth.begin(), depth.end(), 0);
    int right = n;
    while (d < ub) {
      int v = 0;
      for (int i = 0; i < right; ++i) {
        if (n_ch[i] == 0) {
          v = i;
        }
      }
      bool found = false;
      bool stop = false;
      for (int i = n - 1; i >= 0; --i) {
        if (depth[v] - depth[i] == 2 && n_ch[i] < 2) {
          n_ch[par[v]]--;
          par[v] = i;
          n_ch[i]++;
          depth[v]--;
          ub--;
          found = true;
          if (ub <= d) {
            stop = true;
            break;
          }
        }
      }
      if (!found) right--;
      if (stop) {
        break;
      }
    }
    puts("YES");
    for (int i = 1; i < n; ++i) {
      cout << par[i] + 1;
      if (i == n - 1)
        puts("");
      else
        cout << ' ';
    }
  }
  return 0;
}
