#include <bits/stdc++.h>
using namespace std;
int T, n, d, mn[5005], mx[5005], ans[5005], dfs_clock;
void dfs(int x, int tot, int fa) {
  if (x == 0) return;
  int t = ++dfs_clock;
  ans[t] = fa;
  if (mn[x - 1] + x - 1 <= tot)
    dfs(x - 1, tot - x + 1, t);
  else {
    int L = x - 1 >> 1, R = x - 2, M, f = tot - x + 1;
    while (L < R) {
      M = L + R >> 1;
      if (mx[x - 1 - M] + mx[M] < f)
        L = M + 1;
      else
        R = M;
    }
    int tmp = max(mn[L], f - mx[x - 1 - L]);
    dfs(L, tmp, t);
    dfs(x - 1 - L, f - tmp, t);
  }
}
int main() {
  for (int i = 2; i <= 5000; i++) mn[i] = mn[i >> 1] + 1;
  for (int i = 2; i <= 5000; i++) mn[i] += mn[i - 1];
  for (int i = 2; i <= 5000; i++) mx[i] = (i - 1) * i >> 1;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &d);
    if (mx[n] < d || d < mn[n]) {
      puts("NO");
      continue;
    }
    dfs_clock = 0;
    dfs(n, d, 0);
    puts("YES");
    for (int i = 2; i <= n; i++) printf("%d ", ans[i]);
    puts("");
  }
  return 0;
}
