#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int num[N], val[N][N], fa[N];
int n, m;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    if (n * (n - 1) / 2 < m) {
      printf("NO\n");
      continue;
    }
    m = n * (n - 1) / 2 - m;
    for (int i = 1; i <= n; i++) num[i] = 1, val[i][1] = i, fa[i] = i - 1;
    int now = 2;
    for (int i = n; m && i > now; i--) {
      int ret = min(m, i - now);
      m -= ret;
      val[i - ret][++num[i - ret]] = i;
      fa[i] = val[i - ret - 1][(num[i - ret] + 1) / 2];
      if (num[now] == 1 << now - 1) now++;
    }
    if (m)
      printf("NO\n");
    else {
      printf("YES\n");
      for (int i = 2; i <= n; i++) printf("%d%c", fa[i], " \n"[i == n]);
    }
  }
  return 0;
}
