#include <bits/stdc++.h>
using namespace std;
int las[5001];
int fa[5001];
int mark[5001];
int dep[5001];
signed main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, d;
    scanf("%d%d", &n, &d);
    if (d > n * (n - 1) / 2) {
      printf("NO\n");
      continue;
    }
    memset(dep, 0, sizeof(dep));
    memset(fa, 0, sizeof(fa));
    memset(mark, 0, sizeof(mark));
    memset(las, 0, sizeof(las));
    dep[0] = -1;
    for (int i = 1; i <= n; i++) {
      dep[i] = dep[i / 2] + 1;
      d -= dep[i];
      fa[i] = i / 2;
    }
    if (d < 0) {
      printf("NO\n");
      continue;
    }
    int x = n, mx = dep[n];
    while (x) {
      las[dep[x]] = x;
      mark[x] = 1;
      x = fa[x];
    }
    for (int i = n; i >= 1; i--)
      if (!mark[i]) {
        int pre = mx;
        while (dep[fa[i]] < pre && d) {
          fa[i] = las[dep[fa[i]] + 1];
          dep[i] = dep[fa[i]] + 1;
          d--;
          if (dep[i] > mx) {
            mx++;
            las[mx] = i;
            mark[i] = 1;
          }
        }
      }
    printf("YES\n");
    for (int i = 2; i <= n; i++) printf("%d ", fa[i]);
    printf("\n");
  }
  return 0;
}
