#include <bits/stdc++.h>
using namespace std;
int fa[5010], p[5010];
vector<int> v[5010];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, d;
    cin >> n >> d;
    memset(fa, 0, sizeof(fa));
    memset(p, 0, sizeof(p));
    int sum = 0, y = 0;
    for (int i = 1; i <= n;) {
      int x = min(n - i + 1, 1 << y);
      p[y] = x, sum += x * y;
      i += x, y++;
    }
    if (sum > d) {
      cout << "NO" << endl;
      continue;
    }
    while (sum < d) {
      int i = 0;
      for (int k = 1; k <= n; k++)
        if ((p[k] - 1) * 2 >= p[k + 1] + 1) {
          i = k;
          break;
        }
      if (i == 0) break;
      sum++, p[i]--, p[i + 1]++;
    }
    if (sum < d) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    int cnt = 1;
    for (int i = 0; i <= n; i++) v[i].clear();
    v[0].push_back(cnt);
    v[0].push_back(cnt);
    for (int i = 1; i <= n; i++) {
      while (p[i]--) {
        fa[++cnt] = v[i - 1].back();
        v[i - 1].pop_back();
        v[i].push_back(cnt);
        v[i].push_back(cnt);
      }
    }
    for (int i = 2; i <= n; i++) cout << fa[i] << " ";
    cout << "\n";
  }
  return 0;
}
