#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > g;
bool dfs(int curr, int par, int node, int dist, int dep) {
  if (dist == dep && g[par].size() < 2) {
    g[node - 1].clear();
    g[par].push_back(node);
    return true;
  }
  for (auto nbr : g[curr]) {
    if (dfs(nbr, curr, node, dist, dep + 1)) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    int mn = 0;
    queue<int> q;
    q.push(0);
    int cnt = 1;
    g.clear();
    while (cnt < n) {
      int dist = q.front();
      q.pop();
      q.push(dist + 1);
      cnt++;
      mn += dist + 1;
      if (cnt == n) break;
      q.push(dist + 1);
      cnt++;
      mn += dist + 1;
    }
    if (n * (n - 1) / 2 < d || d < mn) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 1; i < n; i++) g[i].push_back(i + 1);
    int amt = n * (n - 1) / 2;
    queue<pair<int, int> > qu;
    qu.push({1, 1});
    int node = n;
    int dep = n - 1;
    while (true) {
      int num = qu.front().first;
      int dist = qu.front().second;
      if (amt - (dep - dist) < d) break;
      amt -= (dep - dist);
      g[node - 1].clear();
      g[num].push_back(node);
      if (g[num].size() == 2) {
        qu.pop();
        for (auto nbr : g[num]) qu.push({nbr, dist + 1});
      }
      if (amt == d) break;
      node--;
      dep--;
    }
    int diff = amt - d;
    if (diff) dfs(1, 0, node, dep - diff, 0);
    vector<int> ans(n + 1, -1);
    for (int i = 1; i <= n; i++) {
      for (auto nbr : g[i]) ans[nbr] = i;
    }
    for (int i = 2; i < n + 1; i++) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
