#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
template <typename T, typename U>
inline void mnze(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void mxze(T &x, U y) {
  if (x < y) x = y;
}
void _scan(int &x) { scanf("%d", &x); }
void _scan(long long &x) { scanf("%lld", &x); }
void _scan(double &x) { scanf("%lf", &x); }
void _scan(char &x) { scanf(" %c", &x); }
void _scan(char *x) { scanf("%s", x); }
template <typename T>
void _scan(vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) _scan(v[i]);
}
void scan() {}
template <typename T, typename... U>
void scan(T &head, U &...tail) {
  _scan(head);
  scan(tail...);
}
template <typename T>
void _dbg(const char *sdbg, T h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename T, typename... U>
void _dbg(const char *sdbg, T h, U... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
long long MOD = 1e9 + 7;
inline long long Msum(long long x) { return x; }
template <typename... Rest>
inline long long Msum(long long x, Rest... rest) {
  return (x + Msum(rest...)) % MOD;
}
inline long long Mprod(long long x) { return x; }
template <typename... Rest>
inline long long Mprod(long long x, Rest... rest) {
  return x * Mprod(rest...) % MOD;
}
inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; }
const int MAXN = 5e3 + 3;
int p[MAXN];
int dd[MAXN];
int sum(int l, int r) { return (r + l) * (r - l + 1) / 2; }
int main() {
  int TC;
  scan(TC);
  while (TC--) {
    int n, D;
    scan(n, D);
    for (int i = 0; i <= n; i++) dd[i] = 0;
    int d = 0;
    dd[1] = 0;
    queue<int> q;
    q.push(1);
    q.push(1);
    for (int v = 2; v <= n && d < D; v++) {
      int u = q.front();
      q.pop();
      p[v] = u;
      dd[v] = dd[u] + 1;
      d += dd[v];
      q.push(v);
      q.push(v);
      int x = n - v;
      if (x && d + sum(dd[v] + 1, dd[v] + x) == D) {
        for (int w = v + 1; w <= n; w++) {
          p[w] = w - 1;
          dd[w] = dd[w - 1] + 1;
          d += dd[w];
        }
        assert(D == d);
        break;
      }
      if (x > 1 && d + sum(dd[v] + 1, dd[v] + x - 1) <= D &&
          d + sum(dd[v] + 1, dd[v] + x - 1) + (dd[v] + x - 1) >= D) {
        int nd = d + sum(dd[v] + 1, dd[v] + x - 1);
        int dn = D - nd;
        if (dn > dd[v] && dn <= dd[v] + x - 1) {
          for (int w = v + 1; w < n; w++) {
            p[w] = w - 1;
            dd[w] = dd[w - 1] + 1;
            d += dd[w];
            if (dd[w] == dn) {
              p[n] = p[w];
              dd[n] = dd[w];
              d += dd[n];
            }
          }
          assert(p[n] != 0);
          assert(D == d);
          break;
        }
      }
    }
    if (d != D || (d == D && dd[n] == 0)) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (int i = 2; i <= n; i++) printf("%d ", p[i]);
    printf("\n");
  }
}
