#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    int D = (int)(ceil(log2(n + 1))) - 1;
    int minsd = (n + 1) * D - (1 << (D + 1)) + 2;
    if (d < minsd || d > (n * (n - 1) / 2)) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    int *dep = new int[n + 1], p[n + 1], c[n + 1];
    vector<int> v;
    for (int i = 0; i < n + 1; i++) {
      v.push_back(i);
      c[i] = 0;
    }
    for (int i = 0; i < n + 1; i++) {
      p[i] = (i >> 1);
      if (2 * i <= n) c[i]++;
      if (2 * i + 1 <= n) c[i]++;
      dep[i] = (int)ceil(log2(i + 1)) - 1;
    }
    auto fun = [dep](int a, int b) { return dep[a] < dep[b]; };
    for (int sd = minsd + 1; sd <= d && sd <= n * (n - 1) / 2; sd++) {
      sort(v.begin(), v.end(), fun);
      int a = -1, b = -1, i = 1;
      while (i <= n) {
        int a1 = -1, b1 = -1;
        int de = dep[v[i]];
        while (i <= n && dep[v[i]] == de) {
          if (a1 == -1 && c[v[i]] == 0)
            a1 = v[i];
          else if (a1 != -1 && c[v[i]] < 2)
            b1 = v[i];
          if (b1 == -1 && c[v[i]] == 1) b1 = v[i];
          if (a1 != -1 && b1 != -1) break;
          i++;
        }
        if (a1 != -1 && b1 != -1) {
          a = a1;
          b = b1;
          break;
        }
      }
      c[p[a]]--;
      p[a] = b;
      c[b]++;
      dep[a]++;
    }
    for (int i = 2; i <= n; i++) cout << p[i] << " ";
    cout << endl;
  }
}
