#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, maxn = 5010;
int pre[maxn], dep[maxn], node[maxn];
bool flag[maxn];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(flag, false, sizeof flag);
    int n, d;
    cin >> n >> d;
    int maxd = 0;
    node[0] = 1;
    for (int i = 2; i <= n; i++) {
      pre[i] = i / 2;
      dep[i] = dep[pre[i]] + 1;
      d -= dep[i];
      maxd = max(maxd, dep[i]);
    }
    if (d < 0) {
      cout << "NO\n";
      continue;
    }
    int idx = n;
    while (idx) {
      node[dep[idx]] = idx;
      flag[idx] = true;
      idx = pre[idx];
    }
    for (int i = n; i >= 1; i--) {
      if (flag[i]) continue;
      int tmp = maxd;
      while (dep[pre[i]] < tmp && d) {
        pre[i] = node[dep[i]];
        dep[i]++;
        if (dep[i] > maxd) {
          maxd++;
          node[maxd] = i;
          flag[i] = 1;
        }
        d--;
      }
    }
    if (d) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (int i = 2; i <= n; i++) {
      cout << pre[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
