#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 5000 + 5;
const int MOD = 1e9 + 7;
const double pi = cos(-1);
int n, d, ans[MAXN], fa[MAXN];
int c, now, maxx, cnt, pos;
int ch[MAXN];
int getdepth() {
  int ans_t = now;
  c++;
  if (c == maxx) {
    c = 1;
    maxx *= 2;
    now++;
  }
  return ans_t;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> d;
    cnt = 0;
    memset(ch, 0, sizeof ch);
    for (int i = 1; i <= n - 1; i++) {
      cnt += i;
      ans[i] = i;
    }
    pos = n - 1, now = 1, c = 1, maxx = 2;
    if (cnt < d) {
      printf("NO\n");
      continue;
    }
    while (cnt > d) {
      int dep = getdepth();
      if (dep >= pos) break;
      if (cnt - (pos - dep) >= d) {
        cnt -= (pos - dep);
        ans[pos] = dep;
      } else {
        ans[pos] -= (cnt - d);
        cnt = d;
      }
      pos--;
    }
    if (cnt > d)
      printf("NO\n");
    else {
      printf("YES\n");
      ans[0] = 0;
      for (int i = 1; i <= n - 1; i++) {
        for (int j = 0; j <= n - 1; j++) {
          if (ans[j] == ans[i] - 1 && ch[j] < 2) {
            ch[j]++;
            fa[i] = j;
            break;
          }
        }
      }
      for (int i = 1; i <= n - 1; i++) printf("%d ", fa[i] + 1);
      printf("\n");
    }
  }
  return 0;
}
