#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, d;
  cin >> n >> d;
  if (n * (n - 1) / 2 < d) {
    cout << "NO\n";
    return;
  }
  vector<int> parent(n + 1);
  vector<int> depth(n + 1);
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    depth[i] = depth[i / 2] + 1;
    parent[i] = i / 2;
    ans += depth[i];
  }
  if (ans > d) {
    cout << "NO\n";
    return;
  }
  if (ans == d) {
    cout << "YES\n";
    for (int i = 2; i <= n; i++) cout << parent[i] << ' ';
    cout << '\n';
    return;
  }
  int nrLeft = -1;
  for (int i = 1; i <= n; i *= 2) nrLeft = i;
  vector<int> leaves;
  for (int i = n; i >= 2; i--) {
    bool ifLeft = 0;
    for (int j = 1; j < 16; j++)
      if (((1 << j) ^ i) == 0) ifLeft = 1;
    if (ifLeft == 0) leaves.push_back(i);
  }
  vector<int> rep(n + 1);
  for (int i = 1; i <= 15; i++) {
    int j = (1 << i);
    if (j > n) break;
    rep[i] = j;
  }
  int helper = leaves[0];
  int pLeaves = 0;
  while (ans < d) {
    if (helper == -1) {
      pLeaves++;
      helper = leaves[pLeaves];
    }
    depth[helper]++;
    int newParent = rep[depth[helper] - 1];
    if (newParent == nrLeft) {
      nrLeft = helper;
      parent[helper] = newParent;
      rep[depth[helper]] = helper;
      helper = -1;
    } else
      parent[helper] = newParent;
    ans++;
  }
  cout << "YES\n";
  for (int i = 2; i <= n; i++) cout << parent[i] << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
