#include <bits/stdc++.h>
using namespace std;
const int N = 5e3;
vector<int> lvl[N + 100];
int ext[N + 100], par[N + 100];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    for (int i = 0; i <= N; i++) {
      lvl[i].clear();
      ext[i] = 1;
    }
    int n, d;
    scanf("%d%d", &n, &d);
    int mn = 0, mx = 0;
    for (int i = 1; i <= n; i++) {
      mx += i - 1;
      int cnt = 0;
      int cur = i;
      while (cur) {
        cur /= 2;
        cnt++;
      }
      mn += cnt - 1;
    }
    if (d < mn || d > mx) {
      printf("NO\n");
    } else {
      for (int i = 1; i <= n; i++) {
        lvl[i - 1].push_back(i);
      }
      printf("YES\n");
      int lst = 1;
      for (int i = n; mx > d; i--) {
        lvl[i - 1].pop_back();
        int cur = i - 1;
        int minus = min(cur - lst, mx - d);
        lvl[cur - minus].push_back(i);
        ext[cur - minus]--;
        ext[cur - minus + 1] += 2;
        if (ext[lst] == 0) {
          lst++;
        }
        mx -= minus;
      }
      for (int i = 0;; i++) {
        if (lvl[i].empty()) {
          break;
        }
        for (int sz = lvl[i].size(), j = 0; j < sz; j++) {
          int check = lvl[i + 1].size();
          if (j * 2 < check) {
            par[lvl[i + 1][j * 2]] = lvl[i][j];
          }
          if (j * 2 + 1 < check) {
            par[lvl[i + 1][j * 2 + 1]] = lvl[i][j];
          }
        }
      }
      for (int i = 2; i <= n; i++) {
        printf("%d ", par[i]);
      }
      printf("\n");
    }
  }
}
