#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 5;
int cnt[MAXN], son[MAXN], fa[MAXN];
vector<int> E[MAXN];
void solve() {
  int n, d, sum = 0;
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
    son[i + 1] = 0;
    E[i].clear();
    cnt[i]++;
    sum += (i);
  }
  if (sum < d) {
    puts("NO");
    return;
  }
  int l = 1, r = n - 1;
  bool flag = true;
  while (sum > d && flag) {
    int det = sum - d;
    if (l >= r) {
      flag = false;
      break;
    }
    if (det > r - l) {
      sum -= r - l;
      cnt[r]--;
      r--;
      cnt[l]++;
    } else {
      cnt[r - det]++;
      cnt[r]--;
      sum -= det;
    }
    if (cnt[l] == (1 << l)) l++;
  }
  if (!flag)
    puts("NO");
  else {
    puts("YES");
    E[0].push_back(1);
    int now = 2;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < cnt[i]; j++) {
        int f = *prev(E[i - 1].end());
        son[f]++;
        fa[now] = f;
        E[i].push_back(now);
        if (son[f] == 2) E[i - 1].pop_back();
        now++;
      }
    }
    assert(now == n + 1);
    for (int i = 2; i <= n; i++) printf("%d ", fa[i]);
    puts("");
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
