#include <bits/stdc++.h>
using namespace std;
const int N = 202019;
int n, d;
bool ed[N];
int dep[N], son[N], fa[N];
bool check() {
  if (d > n * (n - 1) / 2) return false;
  int d1 = 0, a = 1, b = 1, low = 0;
  for (int i = 1; i <= n; i++) {
    if (a)
      low += d1, --a;
    else
      b <<= 1, a = b, ++d1, --i;
  }
  return d >= low;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  int aq = read();
  while (aq--) {
    n = read();
    d = read();
    for (int i = 1; i <= n; i++)
      fa[i] = i - 1, son[i] = 1, dep[i] = i, ed[i] = 0;
    if (!check()) {
      puts("NO");
      continue;
    }
    int dc = n * (n - 1) / 2;
    son[n] = 0;
    dep[0] = 1e9;
    dep[n + 1] = -1;
    while (dc > d) {
      int a = 0;
      for (int i = 1; i <= n; i++)
        if (!ed[i] && dep[i] < dep[a] && !son[i]) a = i;
      int b = n + 1;
      for (int i = 1; i <= n; i++)
        if (son[i] < 2 && dep[i] <= dep[a] - 2 && dep[i] > dep[b]) b = i;
      if (b > n)
        ed[a] = 1;
      else if (dep[b] == dep[a] - 2) {
        --son[fa[a]];
        ++son[b];
        --dep[a];
        fa[a] = b;
        --dc;
      }
    }
    puts("YES");
    for (int i = 2; i <= n; i++) cout << fa[i] << " ";
    cout << endl;
  }
  return 0;
}
