#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, d;
    scanf("%d%d", &n, &d);
    int mi = 0, mx = 0, tmp = n - 1, k = 2, max = 1;
    mx = n * (n - 1) / 2;
    int ans[5001] = {};
    while (tmp > 0) {
      ans[max] = min(k, tmp);
      mi += min(k, tmp) * max;
      tmp -= min(k, tmp);
      max++;
      k *= 2;
    }
    if (d > mx || d < mi) {
      printf("NO\n");
      continue;
    }
    tmp = max - 1;
    int sum = mi;
    while (sum != d) {
      if (ans[tmp] == 1) tmp--;
      ans[tmp]--;
      if (max - tmp >= d - sum) {
        ans[tmp + d - sum]++;
        sum = d;
      } else {
        sum += (max - tmp);
        ans[max]++;
        max++;
      }
    }
    printf("YES\n");
    vector<int> abc, xyz;
    tmp = 1;
    int curr = 2;
    abc.push_back(1);
    while (1) {
      if (ans[tmp] == 0) break;
      for (int i = 0; i < ans[tmp]; i++) {
        printf("%d ", abc[i / 2]);
        xyz.push_back(curr);
        curr++;
      }
      tmp++;
      swap(abc, xyz);
      xyz.clear();
    }
    printf("\n");
  }
}
