#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int dep[N], p[N];
int n, d;
vector<int> v_in_dep[N];
int main() {
  ios::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> d;
    for (int i = 0; i <= n; i++) {
      v_in_dep[i].clear();
    }
    dep[0] = -1;
    int now = 0;
    if (n * (n - 1) / 2 < d) {
      cout << "NO" << endl;
      continue;
    }
    for (int i = 1; i <= n; i++) {
      p[i] = i / 2;
      dep[i] = dep[p[i]] + 1;
      v_in_dep[dep[i]].push_back(i);
      now += dep[i];
    }
    if (d < now) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    d -= now;
    while (d) {
      int q = n;
      while (v_in_dep[q].size() < 2) q--;
      if (v_in_dep[q].size() == 1) {
        q--;
        continue;
      }
      int j = v_in_dep[q].back();
      v_in_dep[q].pop_back();
      p[j] = v_in_dep[q][0];
      v_in_dep[q + 1].push_back(j);
      d--;
    }
    for (int i = 2; i <= n; i++) cout << p[i] << " ";
    cout << endl;
  }
  return 0;
}
