#include <bits/stdc++.h>
using namespace std;
int n, d;
vector<long long> p, v, dep, u;
void solve() {
  cin >> n >> d;
  if (2 * d > n * (n - 1)) {
    cout << "NO\n";
    return;
  }
  int val = 0;
  int num = 1;
  int cur = 1;
  int sum = 0;
  u.assign(n + 1, 0);
  dep.assign(n + 1, 0);
  v.clear();
  for (int i = 0; i < n; ++i) {
    if (cur == 0) {
      ++val;
      num *= 2;
      cur = num;
    }
    if (cur == num) {
      v.push_back(i + 1);
      u[i + 1] = 1;
    }
    dep[i + 1] = val;
    sum += val;
    --cur;
  }
  if (d < sum) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  p.resize(n + 1);
  for (int i = 2; i <= n; ++i) p[i] = i / 2;
  for (int i = n; i > 1; --i) {
    if (sum == d) continue;
    if (u[i]) continue;
    int max_dep = v.size();
    if (max_dep - dep[i] <= d - sum) {
      sum += max_dep - dep[i];
      p[i] = v.back();
      v.push_back(i);
    } else {
      int new_dep = dep[i] + d - sum;
      p[i] = v[new_dep - 1];
      i = 0;
    }
  }
  for (int i = 2; i <= n; ++i) cout << p[i] << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
