#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 1e6 + 5;
bool pw2(int i) { return (i & (i - 1)) == 0; }
int n, d;
void solve() {
  cin >> n >> d;
  int cur = n * (n - 1) / 2;
  if (d > cur) {
    cout << "NO\n";
    return;
  }
  int lb = 0;
  for (int i = 1, r = 0; i <= n; i++) {
    if (pw2(i)) r++;
    lb += r - 1;
  }
  if (d < lb) {
    cout << "NO\n";
    return;
  }
  vector<int> par(n), ch(n), depth(n);
  vector<bool> done(n, false);
  for (int i = 0; i < n; i++) {
    par[i] = i - 1;
    depth[i] = i;
    ch[i] = i < n - 1 ? 1 : 0;
  }
  while (cur > d) {
    int x = -1;
    for (int i = 0; i < n; i++) {
      if (ch[i] == 0 && !done[i] && (x == -1 || depth[x] > depth[i])) {
        x = i;
      }
    }
    if (x == -1) break;
    int p = -1;
    for (int i = 0; i < n; i++) {
      if (depth[i] <= depth[x] - 2 && ch[i] < 2 &&
          (p == -1 || depth[p] < depth[i])) {
        p = i;
      }
    }
    if (p == -1) {
      done[x] = true;
      continue;
    }
    assert(x != -1 && p != -1);
    cur--;
    ch[par[x]]--;
    par[x] = p;
    ch[p]++;
    depth[x]--;
  }
  if (cur > d) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
