#include <bits/stdc++.h>
using namespace std;
void IO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
vector<pair<int, int>> ans;
int n, d;
bool dfs(int cnt, int sum, int dep, int limit) {
  if (cnt * dep > sum) return false;
  if (cnt == 0 && sum == 0) return true;
  for (int i = 1; i <= min(limit, cnt); i++) {
    if (i * dep > sum) return false;
    if (dfs(cnt - i, sum - i * dep, dep + 1, i * 2)) {
      ans.emplace_back(dep, i);
      return true;
    }
  }
  return false;
}
void solve() {
  ans.clear();
  int mx = 0, mn = 0;
  cin >> n >> d;
  mx = n * (n - 1) / 2;
  for (int i = 0, tem = 1, nn = n; nn; i++, nn -= min(nn, tem), tem *= 2)
    mn += i * min(tem, nn);
  if (dfs(n - 1, d, 1, 2)) {
    cout << "YES" << '\n';
    reverse(ans.begin(), ans.end());
    vector<int> pre(1, 1), pp;
    int id = 1;
    for (auto x : ans) {
      pp.clear();
      for (int i = 0; i < x.second; i++)
        cout << pre[i / 2] << ' ', pp.push_back(++id);
      pre = pp;
    }
    cout << '\n';
  } else
    cout << "NO" << '\n';
}
int main() {
  IO();
  int _;
  cin >> _;
  while (_--) solve();
}
