#include <bits/stdc++.h>
using namespace std;
long long solve();
signed main() {
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
long long solve() {
  long long n, d;
  cin >> n >> d;
  vector<long long> cnt(n + 10);
  vector<vector<long long>> tree(n + 10);
  vector<long long> ma(n + 10);
  cnt[0] = 1;
  ma[0] = 1;
  tree[0].push_back(1);
  long long sum = 0;
  for (long long i = 1; i < n; i++) {
    cnt[i] = 1;
    tree[i].push_back(i + 1);
    sum += i;
    ma[i] = min(10000ll, ma[i - 1] * 2);
  }
  long long mi = 0;
  long long mitmp = 4;
  long long pu = 1;
  for (long long i = 2; i <= n; i++) {
    mi += pu;
    if (i == mitmp - 1) {
      mitmp *= 2;
      pu++;
    }
  }
  long long end = n - 1;
  if (sum < d || d < mi) {
    cout << "NO" << endl;
    return 0;
  }
  long long idx = end;
  while (sum > d) {
    if (ma[idx - 1] == cnt[idx - 1]) {
      end--;
      idx = end;
    }
    sum--;
    cnt[idx]--;
    long long num = tree[idx].back();
    tree[idx].pop_back();
    idx--;
    cnt[idx]++;
    tree[idx].push_back(num);
  }
  idx = 1;
  vector<long long> ans(n + 1);
  while (1) {
    if (cnt[idx] == 0) break;
    for (long long i = 0; i < cnt[idx]; i++) {
      ans[tree[idx][i]] = tree[idx - 1][i / 2];
    }
    idx++;
  }
  cout << "YES" << endl;
  cout << ans[2];
  for (long long i = 3; i < ans.size(); i++) cout << " " << ans[i];
  cout << endl;
  return 0;
}
