#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807ll;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, inf = 2147483647,
          nmax = 5005;
int g[nmax], dad[nmax], dep[nmax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  cin >> test;
  while (test--) {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i <= n + 1; ++i) g[i] = dad[i] = dep[i] = 0;
    int all = 0;
    for (int i = 2; i <= n; ++i) {
      dad[i] = i - 1, ++g[i - 1], dep[i] = i - 1;
      all += dep[i];
    }
    if (k > all) {
      cout << "NO\n";
      continue;
    }
    while (all != k) {
      int nod = -1, mx = 0;
      for (int i = 1; i <= n; ++i)
        if (g[i] == 0) mx = max(mx, dep[i]);
      for (int i = 1; i <= n; ++i)
        if (g[i] == 0 && dep[i] == mx) {
          nod = i;
          break;
        }
      if (nod == -1) break;
      int b4 = all;
      all -= dep[nod];
      --g[dad[nod]];
      int sol = inf, soli = -1;
      for (int i = 1; i <= n; ++i)
        if (g[i] != 2 && i != nod && i != dad[nod]) {
          if (abs(k - (all + dep[i] + 1)) < sol) {
            sol = abs(k - (all + dep[i] + 1));
            soli = i;
          }
        }
      if (soli == -1) break;
      ++g[soli];
      dad[nod] = soli;
      dep[nod] = dep[soli] + 1;
      all += dep[nod];
      if (all >= b4) break;
    }
    if (all != k) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (int i = 2; i <= n; ++i) cout << dad[i] << " ";
    cout << "\n";
  }
  return 0;
}
