#include <bits/stdc++.h>
long long t, n, d, fa[1000005], dep[1000005];
long long read() {
  char c = getchar();
  long long ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return ans;
}
void Write(long long x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
void solve() {
  long long sum = 0, pos;
  dep[0] = -1;
  for (long long i = 1; i <= n; i++) {
    fa[i] = i / 2, dep[i] = dep[i / 2] + 1, sum += dep[i];
    if (!(i & (i - 1))) pos = i;
  }
  if (d < sum) return printf("NO\n"), void();
  d -= sum;
  for (long long i = n; i && d; i--) {
    if (!(i & (i - 1))) continue;
    d -= dep[pos] + 1 - dep[i];
    if (d <= 0) {
      while (d) pos = fa[pos], ++d;
      fa[i] = pos;
    }
    fa[i] = pos, dep[i] = dep[pos] + 1, pos = i;
  }
  if (d) return printf("NO\n"), void();
  printf("YES\n");
  for (long long i = 2; i <= n; i++) Write(fa[i]), putchar(' ');
  return putchar('\n'), void();
}
int main() {
  t = read();
  while (t--) n = read(), d = read(), solve();
  return 0;
}
