#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ans = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
  return ans;
}
int fa[5005], cnt[5005], sum[5005], dep[5005], bad[5005];
int main() {
  sum[1] = 1;
  for (int i = 2; i < 5005; i++) sum[i] = i + sum[i / 2] + sum[i - i / 2 - 1];
  for (int i = 1; i < 5005; i++) sum[i] -= i;
  for (int T = read(); T; T--) {
    int n, d;
    n = read(), d = read();
    int cur = n * (n - 1) / 2;
    if (d < sum[n] || d > cur) {
      puts("NO");
      continue;
    }
    fa[1] = 0;
    for (int i = 2; i <= n; i++) fa[i] = i - 1;
    for (int i = 1; i < n; i++) cnt[i] = 1;
    cnt[n] = 0;
    for (int i = 1; i <= n; i++) bad[i] = 0, dep[i] = i - 1;
    while (cur > d) {
      int u;
      for (u = 1; u <= n; u++)
        if (!cnt[u] && !bad[u]) break;
      bad[u] = 1;
      for (int p = 1; p <= n; p++)
        if (cnt[p] < 2 && dep[u] - dep[p] == 2) {
          --cnt[fa[u]], fa[u] = p;
          dep[u] = dep[p] + 1, ++cnt[p];
          bad[u] = 0, --cur;
          break;
        }
    }
    puts("YES");
    for (int i = 2; i <= n; i++) printf("%d%c", fa[i], " \n"[i == n]);
  }
  return 0;
}
