#include <bits/stdc++.h>
using namespace std;
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
int sums[5010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  sums[0] = 0;
  for (auto((i)) = (0); ((i)) < ((5000)); ++((i)))
    sums[i + 1] = sums[i] + i + 1;
  int tcs;
  cin >> tcs;
  while (tcs--) {
    int n, d;
    cin >> n >> d;
    int maximum = sums[n - 1];
    int minimum = 0;
    for (int nodes = n, depth = 0; nodes;
         nodes = max(0, nodes - (1 << depth++)))
      minimum += min(nodes, 1 << depth) * depth;
    if (minimum > d || d > maximum) {
      cout << "NO" << endl;
      continue;
    }
    vector<int> parent(n, -1), childs(n, 1);
    childs.back() = 0;
    set<pair<int, int> > goodLeaves;
    goodLeaves.emplace(n - 1, n - 1);
    vector<int> depth(n);
    iota((depth).begin(), (depth).end(), 0);
    iota((parent).begin(), (parent).end(), -1);
    int val = sums[n - 1];
    while (val > d) {
      auto [de, leave] = *goodLeaves.begin();
      goodLeaves.erase(goodLeaves.begin());
      int p = -1;
      if (depth[leave] > 1)
        for (auto((i)) = (0); ((i)) < ((n)); ++((i)))
          if (depth[i] == de - 2 && childs[i] < 2) p = i;
      if (p == -1) continue;
      if (--childs[parent[leave]] == 0)
        goodLeaves.emplace(depth[parent[leave]], parent[leave]);
      ++childs[p];
      parent[leave] = p;
      --depth[leave];
      val--;
      goodLeaves.emplace(de - 1, leave);
    }
    cout << "YES" << endl;
    for (auto(i) = (1); (i) < (n); ++(i)) cout << parent[i] + 1 << ' ';
    cout << endl;
  }
  return 0;
}
