#include <bits/stdc++.h>
using namespace std;
int n, d;
void solve() {
  cin >> n >> d;
  if (n * (n - 1) / 2 < d) {
    cout << "NO\n";
    return;
  }
  vector<int> lvl(n + 1, 0), pr(n + 1, 0);
  vector<vector<int>> last(n + 1);
  ;
  lvl[0] = 1;
  lvl[1] = 1;
  last[0].push_back(1);
  for (int i = 2; i <= n; i++) {
    lvl[i] = 1;
    pr[i] = i - 1;
    last[i - 1].push_back(i);
  }
  int cur = n * (n - 1) / 2;
  int le = n - 1;
  int l = le;
  while (cur > d) {
    int node = last[le][0];
    l = le;
    bool f = 0;
    l--;
    while (cur > d && lvl[l] < pow(2, l)) {
      f = 1;
      lvl[l]++;
      lvl[l + 1]--;
      last[l].push_back(node);
      pr[node] = last[l - 1][((lvl[l] + 1) / 2) - 1];
      last[l + 1].pop_back();
      l--;
      cur--;
    }
    if (!f) break;
    le--;
  }
  if (cur > d)
    cout << "NO\n";
  else {
    cout << "YES\n";
    for (int i = 2; i <= n; i++) cout << pr[i] << " \n"[i == n];
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ;
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
