#include <bits/stdc++.h>
using namespace std;
int n, d, ld, rd, cd, pred[200500], dep[200500], cnt[200500], bad[200500];
void solve() {
  cin >> n >> d;
  ld = 0;
  rd = n * (n - 1) / 2;
  cd = -1;
  for (int i = 1; i <= n; i++) {
    if (!(i & (i - 1))) cd++;
    ld += cd;
  }
  if (d < ld || d > rd) {
    cout << "NO" << '\n';
    return;
  }
  for (int i = 0; i < n; i++)
    dep[i] = i, pred[i] = i - 1, cnt[i] = 1, bad[i] = 0;
  cnt[n - 1] = 0;
  int cur = n * (n - 1) / 2;
  while (cur > d) {
    int v = -1;
    for (int i = 0; i < n; i++)
      if (!bad[i] && !cnt[i] && (v == -1 || dep[i] < dep[v])) v = i;
    int pr = -1;
    for (int i = 0; i < n; i++)
      if (cnt[i] < 2 && dep[i] < dep[v] - 1 && (pr == -1 || dep[pr] < dep[i]))
        pr = i;
    if (pr == -1) {
      bad[v] = 1;
      continue;
    }
    cnt[pr]++;
    dep[v]--;
    cnt[pred[v]]--;
    pred[v] = pr;
    cur--;
  }
  cout << "YES" << '\n';
  for (int i = 1; i < n; i++) cout << pred[i] + 1 << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
