#include <bits/stdc++.h>
using namespace std;
int ans[5005];
int vis[5005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    for (int i = 2; i <= n; i++) ans[i] = i - 1, vis[i] = 0;
    vis[1] = 0;
    int now = n * (n - 1) / 2;
    if (now < d) {
      printf("NO\n");
      continue;
    }
    int up = 1, dn = n;
    bool f = true;
    queue<int> q, qq;
    q.push(1);
    while (now != d) {
      if (up + 1 == dn) {
        f = false;
        break;
      }
      int res = dn - up - 1;
      if (res > now - d) {
        res = now - d;
        ans[dn] = dn - res - 1;
        break;
      }
      if (q.empty()) {
        while (!qq.empty()) q.push(qq.front()), qq.pop();
        up++;
        q.push(up);
        continue;
      }
      ans[dn] = q.front();
      q.pop();
      qq.push(dn);
      qq.push(dn);
      dn--;
      now -= res;
    }
    if (f) {
      printf("YES\n");
      for (int i = 2; i <= n; i++) printf("%d ", ans[i]);
      printf("\n");
    } else
      printf("NO\n");
  }
}
