#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int dep[N], fa[N];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, d;
    scanf("%d%d", &n, &d);
    dep[0] = -1;
    int pos, res = 0;
    for (int i = 1; i <= n; i++) {
      fa[i] = i >> 1;
      dep[i] = dep[i >> 1] + 1;
      res += dep[i];
      if (!(i & (i - 1))) pos = i;
    }
    d -= res;
    if (d < 0) {
      puts("NO");
      continue;
    }
    if (d == 0) {
      puts("YES");
      for (int i = 2; i <= n; i++) printf("%d ", fa[i]);
      puts("");
      continue;
    }
    for (int i = n; i; i--) {
      if ((i & (i - 1)) == 0) continue;
      d -= dep[pos] + 1 - dep[i];
      if (d <= 0) {
        while (d) pos = fa[pos], d++;
        d = 0;
        fa[i] = pos;
        break;
      }
      fa[i] = pos, dep[i] = dep[pos] + 1, pos = i;
    }
    if (d == 0) {
      puts("YES");
      for (int i = 2; i <= n; i++) printf("%d ", fa[i]);
      puts("");
      continue;
    } else
      puts("NO");
  }
}
