#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
int min_depth[N], max_depth[N];
void prec() {
  for (int n = 1; n <= 5000; n++) {
    int nn = n - 1, h = 0, cnt = 1;
    while (nn) {
      h++;
      cnt *= 2;
      min_depth[n] += min(nn, cnt) * h;
      nn -= min(nn, cnt);
    }
    max_depth[n] = n * (n - 1) / 2;
  }
}
int timer = 0;
vector<int> p;
void solver(int root, int n, int d) {
  if (n == 1) return;
  d -= (n - 1);
  for (int l = 0; l <= n - 1; l++) {
    int r = (n - 1) - l;
    if (!(min_depth[l] + min_depth[r] <= d && d <= max_depth[l] + max_depth[r]))
      continue;
    int flag = 0;
    for (int depth_l : {min_depth[l], max_depth[l]}) {
      if (min_depth[r] <= d - depth_l && d - depth_l <= max_depth[r]) {
        if (l) {
          int lv = timer++;
          p.push_back(root);
          solver(lv, l, depth_l);
        }
        if (r) {
          int rv = timer++;
          p.push_back(root);
          solver(rv, r, d - depth_l);
        }
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
}
void solve() {
  int n, d;
  cin >> n >> d;
  if (!(min_depth[n] <= d && d <= max_depth[n])) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  p.clear();
  timer = 2;
  solver(1, n, d);
  for (auto x : p) cout << x << " ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  prec();
  int t;
  cin >> t;
  while (t--) solve();
}
