#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, d;
  cin >> n >> d;
  int D = d;
  vector<int> p(n);
  vector<int> h(n);
  for (int i = 1; i < n; ++i) {
    p[i] = (i + 1) / 2 - 1;
    h[i] = h[(i + 1) / 2 - 1] + 1;
    d -= h[i];
  }
  if (d < 0) {
    cout << "NO";
    return;
  }
  while (d) {
    vector<int> cnt(n);
    for (int i = 0; i < n; ++i) {
      ++cnt[p[i]];
    }
    vector<vector<int>> fr(D + 1);
    for (int i = 0; i < n; ++i) {
      if (cnt[i] < 2) {
        fr[h[i]].push_back(i);
      }
    }
    bool ok = false;
    for (int i = 0; i < n; ++i) {
      if (cnt[i] == 0 and fr[h[i]].size() > 1) {
        for (int it : fr[h[i]]) {
          if (it != i) {
            p[i] = it;
            ++h[i];
            --d;
            ok = true;
            break;
          }
        }
      }
      if (ok) {
        break;
      }
    }
    if (!ok) {
      cout << "NO";
      return;
    }
  }
  cout << "YES\n";
  for (int i = 1; i < n; ++i) {
    cout << p[i] + 1 << ' ';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }
  return 0;
}
