#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 5e3 + 5;
int n, height[N], m, childs[N], par[N], t;
stack<int> c;
void Solve() {
  cin >> n >> m;
  iota(height, height + n + 1, -1);
  iota(par, par + n + 1, -1);
  fill(childs, childs + n, 1);
  childs[n] = 0;
  c.push(n);
  int sum = n * (n - 1) / 2;
  if (sum < m || n >= (1 << 10)) {
    cout << "NO"
         << "\n";
    return;
  }
  while (sum > m && c.size()) {
    auto ch = c.top();
    c.pop();
    for (int i = 1; i <= n; i++) {
      if (i != ch && height[i] == height[ch] - 2 && childs[i] < 2) {
        childs[par[ch]]--;
        if (childs[par[ch]] == 0) {
          c.push(par[ch]);
        }
        height[ch]--;
        par[ch] = i;
        childs[i]++;
        c.push(ch);
        sum--;
        break;
      }
    }
  }
  if (sum == m) {
    cout << "YES"
         << "\n";
    for (int i = 2; i <= n; i++) cout << par[i] << " ";
  } else
    cout << "NO";
  cout << "\n";
  while (c.size()) c.pop();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> t;
  while (t--) Solve();
  return 0;
}
