#include <bits/stdc++.h>
using namespace std;
const int N = 5003;
int T;
int n, m;
int fa[N];
int depth[N];
int sum;
int rep[N];
int main() {
  scanf("%d", &T);
  while (T--) {
    memset(rep, 0, sizeof(rep));
    scanf("%d%d", &n, &m);
    sum = 0;
    for (int i = 2; i <= n; ++i) {
      fa[i] = i / 2;
      depth[i] = depth[fa[i]] + 1;
      sum += depth[i];
    }
    if (m < sum) {
      puts("NO");
      continue;
    }
    for (int i = 1; i <= depth[n]; ++i) rep[i] = (1 << i);
    for (int i = n; i >= 1; --i) {
      if ((i & (i - 1)) == 0) continue;
      while (sum < m) {
        fa[i] = rep[depth[i]];
        ++depth[i];
        ++sum;
        if (!rep[depth[i]]) {
          rep[depth[i]] = i;
          break;
        }
      }
    }
    if (sum < m) {
      puts("NO");
      continue;
    }
    puts("YES");
    for (int i = 2; i <= n; ++i) printf("%d ", fa[i]);
    puts("");
  }
  return 0;
}
