#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
vector<int> g[maxn];
int num[maxn];
int mn, mx;
int n, d;
int ans[maxn], fa[maxn], id[maxn];
bool run() {
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) g[i].clear();
  int rem = n, dep = 0;
  mn = 0;
  for (int i = 0; i <= n; ++i) {
    dep = i;
    if (rem <= (1 << i)) {
      num[i] = rem;
      mn += rem * (i);
      break;
    }
    rem -= (1 << i);
    mn += (1 << i) * (i);
  }
  mx = n * (n - 1) / 2;
  if (d < mn) return false;
  if (d > mx) return false;
  for (int i = 1; i <= n; ++i) ans[i] = 1;
  int down = n, up = 2;
  while (mx > d) {
    ans[down]--;
    if (mx - d > down - up + 1) {
      ans[up]++;
      mx -= down - up;
      if (ans[up] == (1 << (up - 1))) ++up;
    } else {
      for (int j = down + d - mx; j <= n; ++j) {
        if (ans[j] != (1 << (j - 1))) {
          ++ans[j];
          mx -= down - j;
          break;
        }
      }
    }
    --down;
  }
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    if (run()) {
      printf("YES\n");
      int cnt = 1;
      for (int i = 1; i <= n; ++i) {
        if (!ans[i]) break;
        for (int j = 0; j < ans[i]; ++j) g[i].push_back(cnt++);
      }
      for (int i = 2; i <= n; ++i) {
        if (!ans[i]) break;
        for (int j = 0; j < ans[i]; ++j) {
          fa[g[i][j]] = g[i - 1][j >> 1];
        }
      }
      for (int i = 2; i <= n; ++i) printf("%d%c", fa[i], i == n ? '\n' : ' ');
    } else
      printf("NO\n");
  }
  return 0;
}
