#include <bits/stdc++.h>
using namespace std;
void Down_sum(vector<int> &p, vector<int> &l, vector<int> &d, vector<int> &b,
              int &sum, int n) {
  bool f = true, f2 = true;
  while (f) {
    f2 = true;
    f = true;
    int second = 0, md = 1e9;
    for (int i = 2; i <= n; ++i)
      if (b[i] != 1 && l[i] == 1 && d[i] < md) {
        second = i;
        md = d[i];
        f2 = false;
      }
    for (int i = 1; i <= n; ++i)
      if (l[i] != -1 && d[i] == d[second] - 2) {
        --sum;
        --l[i];
        --d[second];
        ++l[p[second]];
        p[second] = i;
        f = false;
        break;
      }
    if (f) b[second] = 1;
    if (f2) {
      sum = -1;
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int t = 100;
  cin >> t;
  while (t--) {
    int n, D;
    cin >> n >> D;
    vector<int> p(n + 1, 0);
    vector<int> d(n + 1, 0), s2(n + 1, 0);
    vector<int> l(n + 1, 1);
    vector<int> b(n + 1, 0);
    int sum = 0, minD = 0;
    for (int i = 2; i <= n; ++i) {
      s2[i] = s2[i / 2] + 1;
      minD += s2[i];
      --l[i - 1];
      p[i] = i - 1;
      d[i] = d[i - 1] + 1;
      sum += d[i];
    }
    if (sum < D || minD > D) {
      cout << "NO\n";
      continue;
    }
    while (sum > D) {
      Down_sum(p, l, d, b, sum, n);
    }
    if (sum == -1) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (int i = 2; i <= n; ++i) cout << p[i] << " ";
    cout << "\n";
  }
  return 0;
}
