#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
int fa[maxn];
set<int> rest;
int main() {
  int w = 2;
  for (int i = 1; i <= 20; i++) {
    rest.insert(w - 1);
    w *= 2;
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, d;
    scanf("%d%d", &n, &d);
    for (int i = 1; i <= n; i++) fa[i] = i - 1;
    int sumdep = (0 + n - 1) * n / 2;
    int nowpos = 1, maxmove = n - 2, twice = 1;
    while (maxmove > 0 && sumdep > d) {
      if (sumdep - maxmove > d) {
        fa[n - maxmove + 1] = nowpos;
        sumdep -= maxmove;
        twice++;
        maxmove -= 1;
        if (twice == 2) {
          if (rest.count(nowpos)) {
            nowpos = nowpos + 1;
            maxmove += 1;
            fa[n - maxmove + 2] = nowpos;
            maxmove = maxmove - 2;
            twice = 1;
          } else {
            nowpos += 1;
            twice = 0;
          }
        }
        continue;
      } else {
        int cut = sumdep - d;
        int togo = fa[n - cut];
        if (togo < n - maxmove + 1 && rest.count(togo) && twice == 0) {
          break;
        } else if (togo <= n - maxmove && togo + 1 <= n - maxmove &&
                   twice == 0) {
          fa[n - cut + 1] = togo + 1;
        } else {
          fa[n - cut + 1] = togo;
        }
        sumdep = d;
        break;
      }
    }
    if (sumdep != d)
      printf("NO\n");
    else {
      printf("YES\n");
      for (int i = 2; i <= n; i++) printf("%d ", fa[i]);
      puts("");
    }
  }
  return 0;
}
