#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
int parent[N];
bool pos(int n, int d) {
  int sum = n * (n - 1) / 2;
  if (sum < d) return 0;
  int x = sum - d;
  int last = 1, now, mx = n - 1;
  g[0].push_back(1);
  for (int i = 1; i <= mx; i++) {
    g[i].push_back(i + 1);
    now = 1;
    while (now < last * 2 && mx - i <= x && mx > i) {
      now++;
      x -= mx - i;
      g[i].push_back(mx + 1);
      mx--;
    }
    last = now;
  }
  if (x) return 0;
  return 1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    if (pos(n, d)) {
      cout << "YES" << endl;
      for (int i = 1; i <= n; i++) {
        for (int j = 0; j < g[i].size(); j++) parent[g[i][j]] = g[i - 1][j / 2];
      }
      for (int i = 2; i <= n; i++) cout << parent[i] << " ";
      cout << endl;
    } else
      cout << "NO" << endl;
    for (int i = 0; i <= n; i++) g[i].clear();
  }
  return 0;
}
