#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, d;
    cin >> n >> d;
    long long int Max = (n * (n - 1)) / 2;
    long long int Min = 0;
    long long int curr_depth = 0;
    for (long long int i = 1; i <= n; i++) {
      if (!(i & (i - 1))) {
        curr_depth++;
      }
      Min += curr_depth - 1;
    }
    if (!(d >= Min && d <= Max)) {
      cout << "NO"
           << "\n";
      continue;
    }
    vector<long long int> children(n, 1);
    children[n - 1] = 0;
    vector<long long int> depth(n);
    for (long long int i = 0; i < n; i++) {
      depth[i] = i;
    }
    vector<long long int> par(n);
    for (long long int i = 0; i < n; i++) {
      par[i] = i - 1;
    }
    vector<long long int> bad(n, 0);
    long long int D = (n * (n - 1)) / 2;
    while (D > d) {
      long long int v = -1;
      for (long long int i = 0; i < n; i++) {
        if (children[i] == 0 && !bad[i] && (v == -1 || depth[i] < depth[v])) {
          v = i;
        }
      }
      long long int p = -1;
      for (long long int i = 0; i < n; i++) {
        if (children[i] < 2 && depth[v] - depth[i] >= 2 &&
            (p == -1 || depth[i] > depth[p])) {
          p = i;
        }
      }
      if (p == -1) {
        bad[v] = 1;
        continue;
      }
      depth[v]--;
      children[par[v]]--;
      children[p]++;
      par[v] = p;
      D--;
    }
    cout << "YES"
         << "\n";
    for (long long int i = 1; i < n; i++) {
      cout << par[i] + 1 << " ";
    }
    cout << "\n";
  }
}
