#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
using namespace std;
int v[5005];
int main() {
  int t1;
  cin >> t1;
  for (int t = 1; t <= t1; t++) {
    int n, d;
    cin >> n >> d;
    memset(v, 0, sizeof(v));
    int l = 1, nr = n - 1;
    v[0] = 1;
    for (; nr >= v[l - 1] * 2; l++) {
      v[l] = v[l - 1] * 2;
      d -= v[l] * l;
      nr -= v[l];
    }
    if (nr == 0)
      l--;
    else
      d -= nr * l, v[l] = nr;
    if (d < 0) {
      cout << "NO\n";
      continue;
    }
    int l2;
    for (l2 = l; d > 0 && l >= 1; l--) {
      if (v[l] == 1) continue;
      if (l2 + 1 - l > d) {
        v[l]--;
        v[l + d]++;
        d = 0;
        break;
      }
      v[++l2] = 1;
      d -= l2 - l;
      v[l]--;
      l++;
    }
    if (d == 0) {
      cout << "YES\n";
      queue<int> p[5005];
      p[0].push(1);
      p[0].push(1);
      for (int i = 1, node = 2; i <= l2; i++)
        if (v[i] > 0) {
          cout << p[i - 1].front() << ' ';
          p[i - 1].pop();
          p[i].push(node);
          p[i].push(node);
          v[i--]--;
          node++;
        }
      cout << '\n';
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
