#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = INT_MAX;
const int N = 5 * 1e3 + 10;
const long double eps = 1e-6;
int p[N], lvl[N];
vector<int> sons[N], g[N];
bool bad(int x) {
  for (int i : g[x - 1]) {
    if (sons[i].size() < 2) return false;
  }
  return true;
}
void solve() {
  int n, d;
  cin >> n >> d;
  if (1) {
    int tmp = 2, sum = 0, c = 1, _n = n;
    --n;
    while (n) {
      sum += min(tmp, n) * c;
      n -= min(n, tmp);
      tmp *= 2;
      ++c;
    }
    if (sum > d) {
      cout << "NO\n";
      return;
    }
    n = _n;
  }
  fill(p, p + n, 0);
  fill(lvl, lvl + n, 0);
  g[0].push_back(1);
  g[1].push_back(2);
  p[2] = 1;
  --d;
  sons[1].push_back(2);
  long long step2 = 2;
  for (int i = 1; i <= n; ++i) {
    lvl[i] = step2;
    step2 = min(step2 * 2, (long long)INT_MAX / 2);
  }
  --lvl[1];
  for (int i = 3; i <= n; ++i) {
    int sum = 0, tmp = n - i, c = 1;
    while (tmp) {
      sum += min(tmp, lvl[c]) * c;
      tmp -= min(tmp, lvl[c]);
      ++c;
    }
    int w = d - sum;
    tmp = w;
    while (w > 0 && bad(w)) --w;
    if (w <= 0) {
      w = max(1, tmp);
      while (bad(w)) ++w;
    }
    d -= w;
    g[w].push_back(i);
    --lvl[w];
    for (int j : g[w - 1]) {
      if (sons[j].size() < 2) {
        sons[j].push_back(j);
        p[i] = j;
        break;
      }
    }
  }
  if (d == 0) {
    cout << "YES\n";
    for (int i = 2; i <= n; ++i) cout << p[i] << " ";
  }
  for (int i = 0; i <= n; ++i) sons[i].clear(), g[i].clear();
  if (d) cout << "NO";
  cout << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
