#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 5;
long long t, n, d, fa[N], dep[N], a[N], mx, ans;
bool vis[N];
signed main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &n, &d);
    memset(vis, 0, sizeof(vis)), mx = 0, a[0] = 1;
    for (long long i = 2; i <= n; i++)
      fa[i] = i / 2, dep[i] = dep[fa[i]] + 1, d -= dep[i], mx = max(mx, dep[i]);
    if (d < 0) {
      puts("NO");
      continue;
    }
    long long x = n;
    while (x) a[dep[x]] = x, vis[x] = 1, x = fa[x];
    for (long long i = n; i >= 1; i--) {
      if (vis[i]) continue;
      long long pre = mx;
      while (dep[fa[i]] < pre && d) {
        fa[i] = a[dep[fa[i]] + 1], dep[i] = dep[fa[i]] + 1;
        if (dep[i] > mx) mx++, a[mx] = i, vis[i] = 1;
        d--;
      }
    }
    if (d) {
      puts("NO");
      continue;
    }
    puts("YES");
    for (long long i = 2; i <= n; i++)
      printf("%lld%c", fa[i], i == n ? '\n' : ' ');
  }
  return 0;
}
