#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, d;
    cin >> n >> d;
    vector<int> v(0);
    int mi = 0, ma = (n * (n + 1)) / 2;
    int i = 0;
    while (n > 0) {
      mi += min(n, (int)pow(2, i)) * i;
      v.push_back(min(n, (int)pow(2, i)));
      n -= min(n, (int)pow(2, i));
      i++;
    }
    if (d < mi || d > ma)
      cout << "NO" << endl;
    else {
      int soma = mi, tam = v.size();
      for (int i = tam - 1; soma != d && i > 0; i--) {
        while (v[i] > 1 && soma != d) {
          if (d - soma >= v.size() - i) {
            soma += v.size() - i;
            v.push_back(1);
          } else {
            v[i + d - soma]++;
            soma = d;
          }
          v[i]--;
        }
      }
      cout << "YES" << endl;
      vector<vector<int> > m(v.size(), vector<int>(0));
      int nod = 1;
      for (int i = 0; i < v.size(); i++) {
        for (int j = nod; j < nod + v[i]; j++) {
          m[i].push_back(j);
        }
        nod += v[i];
      }
      for (int i = 1; i < v.size(); i++) {
        for (int j = 0; j < m[i].size(); j++) {
          cout << m[i - 1][j / 2] << " ";
        }
      }
      cout << endl;
    }
  }
  return 0;
}
