#include <bits/stdc++.h>
using namespace std;
long long int c, n, d, p[5050], cnt[5050];
stack<long long int> s[5050];
int main() {
  ios::sync_with_stdio(false);
  cin >> c;
  while (c--) {
    long long int S = 0, last;
    for (int i = 1; i <= n; i++)
      while (!s[i].empty()) s[i].pop();
    cin >> n >> d;
    last = n;
    cnt[0] = 1;
    for (int i = 1; i <= n; i++) p[i] = i - 1, S += i - 1, s[i].push(i);
    for (int i = 1; i <= n; i++) cnt[i]--;
    {
      while (S > d) {
        bool ok = false;
        for (int i = 1; i < last; i++) {
          if (s[i].size() > 0 and S - ((last - 1) - i) >= d) {
            p[last] = s[i].top(), s[i].pop(), S -= ((last - 1) - i);
            s[i + 1].push(last), s[i + 1].push(last);
            last--;
            ok = true;
            break;
          }
        }
        if (!ok) break;
      }
      if (S == d) {
        cout << "YES\n";
        for (int i = 2; i <= n; i++) cout << p[i] << " ";
        cout << endl;
      } else
        cout << "NO\n";
    }
  }
}
