#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double EPS = 1e-9;
const int N = 5e5 + 9;
set<int> a[5005];
int pr[5005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    for (int i = 1; i <= n; i++) a[i].clear(), pr[i] = i;
    if (d > n * (n - 1) / 2) {
      cout << "NO" << endl;
      continue;
    }
    set<pair<int, int>> k;
    int x = n * (n - 1) / 2;
    for (int i = 1; i <= n - 1; i++)
      a[i].insert(i + 1), k.insert({i, i}), pr[i] = max(1, i - 1);
    k.insert({n, n}), pr[n] = max(1, n - 1);
    while (x > d) {
      auto it = --k.end();
      auto u = *it;
      k.erase(it);
      a[pr[u.second]].erase(u.second);
      int mov = x - d;
      auto cat = k.lower_bound({u.first - mov - 1, -1e9});
      auto v = *cat;
      if (u.first - v.first - 1 <= 0) break;
      x -= u.first - v.first - 1;
      a[v.second].insert(u.second);
      if (a[v.second].size() == 2) k.erase(cat);
      k.insert({v.first + 1, u.second});
      pr[u.second] = v.second;
    }
    if (x == d) {
      cout << "YES" << endl;
      for (int i = 2; i <= n; i++) cout << pr[i] << " ";
      cout << endl;
    } else
      cout << "NO" << endl;
  }
  return 0;
}
