#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int f[N], depth[N], node[N], flag[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    for (int i = 2; i <= n; i++) {
      f[i] = i / 2;
      depth[i] = depth[f[i]] + 1;
      d -= depth[i];
    }
    int maxn = depth[n];
    if (d < 0) {
      cout << "NO\n";
      continue;
    }
    int now = n;
    for (int i = 1; i <= n; i++) flag[i] = 0;
    while (now) {
      flag[now] = 1;
      node[depth[now]] = now;
      now = f[now];
    }
    for (int i = n; i > 1; i--) {
      if (flag[i]) continue;
      int pre = maxn;
      while (d && depth[i] - 1 < pre) {
        f[i] = node[depth[i]];
        depth[i]++;
        if (depth[i] > maxn) {
          maxn = depth[i];
          flag[i] = 1;
          node[depth[i]] = i;
        }
        d--;
      }
    }
    if (d)
      cout << "NO\n";
    else {
      cout << "YES\n";
      for (int i = 2; i <= n; i++) cout << f[i] << " ";
      cout << endl;
    }
  }
  return 0;
}
