#include <bits/stdc++.h>
using namespace std;
queue<int> able[50100];
int fa[50100], lft[50100];
signed main() {
  std::ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n, d;
    cin >> n >> d;
    int now = n * (n - 1) / 2;
    if (now < d) {
      cout << "NO\n";
      continue;
    }
    for (int i = 1; i <= n; i += 1) {
      able[i] = queue<int>();
      able[i].push(i);
      lft[i] = 1;
      fa[i] = i - 1;
    }
    ++lft[n];
    int l = 1, endfg = 0, flag = 0;
    for (int i = n;; i -= 1) {
      while (1) {
        while (able[l].size() && lft[able[l].front()] == 0) able[l].pop();
        if (able[l].empty())
          ++l;
        else
          break;
      }
      if (now == d) break;
      if (now - d > i - 1 - l)
        ;
      else
        l = i - 1 - now + d, endfg = 1;
      if (i - 1 <= l) {
        flag = 1;
        break;
      } else {
        ++lft[fa[i]];
        now -= i - 1 - l;
        fa[i] = able[l].front();
        --lft[able[l].front()];
        able[l + 1].push(i);
      }
    }
    if (flag) {
      cout << "NO" << '\n';
    } else {
      cout << "YES\n";
      for (int i = 2; i <= n; i += 1) {
        cout << fa[i] << ' ';
      }
      cout << '\n';
    }
  }
  return 0;
}
