#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ret = 0, flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') ret = ret * 10 + (c ^ '0'), c = getchar();
  return flag * ret;
}
struct use {
  int x, dis;
};
const int N = 5e3 + 5;
int T, n, d;
vector<int> edge[N];
int dad[N];
int build(int x, int dis) {
  int sum = 0;
  if ((x << 1) <= n) {
    edge[x].push_back(x << 1);
    sum += dis + 1;
    sum += build(x << 1, dis + 1);
  }
  if ((x << 1 | 1) <= n) {
    edge[x].push_back(x << 1 | 1);
    sum += dis + 1;
    sum += build(x << 1 | 1, dis + 1);
  }
  return sum;
}
void bfs() {
  queue<use> q;
  q.push({1, 0});
  int now = 0;
  vector<int> p1, p2;
  while (q.empty() == 0) {
    int x = q.front().x, dis = q.front().dis;
    q.pop();
    if (now != dis) {
      now = dis, p1.clear(), p2.clear();
    }
    for (auto it = edge[x].begin(); it != edge[x].end(); it++) {
      int y = *it;
      if (edge[y].size() == 0) {
        p1.push_back(y);
        if (p2.size()) {
          edge[p2[0]].push_back(y);
          edge[x].erase(it);
          return;
        }
      }
      if (edge[y].size() != 2) p2.push_back(y);
      q.push({y, dis + 1});
    }
  }
}
int main() {
  T = read();
  while (T--) {
    n = read(), d = read();
    for (int i = 1; i <= n; i++) edge[i].clear();
    int mn = build(1, 0);
    int mx = (n - 1) * n / 2;
    if (!(mn <= d && d <= mx)) {
      printf("NO\n");
      continue;
    }
    int now = mn;
    while (now < d) {
      bfs();
      now++;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < edge[i].size(); j++) dad[edge[i][j]] = i;
    }
    printf("YES\n");
    for (int i = 2; i <= n; i++) printf("%d ", dad[i]);
    printf("\n");
  }
  return 0;
}
