#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, d;
  cin >> n >> d;
  int mi = 0, mx = n * (n - 1) / 2;
  for (int i = 0, val = n; val > 0; ++i) {
    int cnt = 1 << i;
    mi += i * (cnt > val ? val : cnt);
    val -= cnt;
  }
  if (d < mi || d > mx) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  vector<int> seq(n + 1, -1);
  int cur = 0;
  for (int i = 1; i <= n; ++cur, i = 1 << cur) {
    seq[i] = cur + 1;
  }
  cur = n;
  for (int i = 1; i <= n; ++i)
    if (seq[i] == -1) seq[i] = cur--;
  vector<int> par(n, 0), dep(n, 0), done(n, 0);
  for (int i = 1; i < n; ++i) {
    par[i] = i - 1;
    dep[i] = i;
    done[i - 1] = 1;
  }
  queue<int> Q;
  for (int i = 1; i <= n; ++i) Q.push(seq[i] - 1);
  cur = mx;
  int node = n - 1;
  while (cur > d) {
    int abv = Q.front();
    if (cur - (dep[node] - dep[abv] - 1) < d) {
      cur -= d;
      while (cur > 0) {
        if (done[par[node] - 1] == 2) {
          done[par[node]] += 1;
          node -= 1;
          continue;
        } else {
          done[par[node]] -= 1;
          par[node] -= 1;
          done[par[node]] += 1;
          dep[node] -= 1;
          --cur;
        }
      }
      break;
    } else {
      ++done[abv];
      if (done[abv] == 2) Q.pop();
      --done[par[node]];
      cur -= (dep[node] - dep[abv] - 1);
      dep[node] = dep[abv] + 1;
      done[node] = 0;
      par[node] = abv;
      node -= 1;
    }
  }
  for (int i = 1; i < n; ++i) cout << par[i] + 1 << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
