#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const long long Inf = 1e11;
int p[maxn];
int num[maxn];
int main() {
  int T;
  cin >> T;
  while (T--) {
    memset(p, 0, sizeof(p));
    memset(num, 0, sizeof(num));
    int n, d;
    cin >> n >> d;
    int mi = 0, ma = 0;
    for (int i = 2; i <= n; i++) ma += (i - 1);
    int tn = n - 1, i = 1;
    num[0] = 1;
    while ((1 << i) <= tn) {
      num[i] = (1 << i);
      tn -= (1 << i);
      mi += i * (1 << i);
      i++;
    }
    if (tn) {
      mi += i * tn;
      num[i] = tn;
    }
    int dep = i;
    if (mi <= d && d <= ma) {
      int k = dep;
      int left = d - mi;
      while (left--) {
        for (int i = k; i >= 1; i--) {
          if (num[i] > 1 && 2 * num[i] - 1 > num[i + 1]) {
            num[i]--, num[i + 1]++;
            dep = max(dep, i + 1);
            k = i + 1;
            break;
          }
        }
      }
      int x = 2, pre = 0, son = 0;
      for (int i = 1; i <= dep; i++) {
        pre = x - num[i - 1];
        son = 0;
        for (int j = 1; j <= num[i]; j++) {
          if (son < 2)
            son++, p[x] = pre;
          else
            pre++, son = 1, p[x] = pre;
          x++;
        }
      }
      printf("YES\n");
      for (int i = 2; i <= n; i++) printf("%d ", p[i]);
      printf("\n");
    } else
      printf("NO\n");
  }
}
