#include <bits/stdc++.h>
using namespace std;
const int maxn = 5100;
int t;
int n, d, cnt = 0;
int depth[maxn];
int deepNum[maxn], finalNum[maxn];
int fa[maxn];
int nodeNum, height;
void init() {
  cnt = 0;
  for (int i = 0; i <= n; i++) {
    finalNum[i] = 0, deepNum[i] = 0;
  }
  for (int i = 0; i <= n - 1; i++)
    depth[i] = i, cnt += i, deepNum[i]++, fa[i] = 0;
  nodeNum = n - 1, height = 1;
}
int getDeep() {
  if (deepNum[height] < pow(2, height)) {
    deepNum[height]++;
  } else {
    height++;
    deepNum[height]++;
  }
  return height;
}
void print() {
  for (int i = 1; i <= n - 1; i++)
    printf("%d%c", depth[i], i == n ? '\n' : ' ');
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> d;
    init();
    if (cnt < d) {
      puts("NO");
      continue;
    }
    while (cnt > d) {
      int height = getDeep();
      if (height >= nodeNum) break;
      int value1 = nodeNum - height;
      int value2 = cnt - d;
      if (value1 <= value2) {
        depth[nodeNum] = height;
        cnt -= value1;
      } else {
        depth[nodeNum] -= value2;
        cnt = d;
      }
      nodeNum--;
    }
    if (cnt != d) {
      puts("NO");
      continue;
    }
    puts("YES");
    for (int i = 1; i <= n - 1; i++) {
      for (int j = 0; j <= n - 1; j++) {
        if (depth[j] == depth[i] - 1 && finalNum[j] < 2) {
          fa[i] = j;
          finalNum[j]++;
          break;
        }
      }
    }
    for (int i = 1; i <= n - 1; i++) {
      printf("%d%c", fa[i] + 1, i == n - 1 ? '\n' : ' ');
    }
  }
  return 0;
}
