#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, ans[N], T, dep[N], cnt[N];
void solve() {
  int sum = 0;
  for (int i = 1; i <= n; i++)
    ans[i] = i - 1, sum += i - 1, dep[i] = i, cnt[i] = 1;
  cnt[n] = 0;
  m -= sum;
  if (m > 0) {
    puts("NO");
    return;
  }
  for (int i = n; i >= 1; i--) {
    if (cnt[i]) continue;
    int num = i, pnt = 0;
    for (int j = 1; j <= n; j++)
      if (cnt[j] <= 1 && (dep[i] - dep[j] - 1) > pnt)
        pnt = dep[i] - dep[j] - 1, num = j;
    if (pnt > -m)
      for (int j = 1; j <= n; j++)
        if (cnt[j] <= 1 && dep[i] - dep[j] - 1 == -m && i != j) {
          num = j;
          break;
        }
    if (num == i) continue;
    cnt[ans[i]]--;
    cnt[num]++;
    ans[i] = num;
    m += dep[i] - dep[num] - 1;
    dep[i] = dep[num] + 1;
    if (m >= 0) break;
  }
  if (m != 0)
    puts("NO");
  else {
    puts("YES");
    for (int i = 2; i <= n; i++) cout << ans[i] << ' ';
    puts("");
  }
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> m;
    solve();
  }
  return 0;
}
