#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int t, n, d, totson[N], f[N], dep[N], isbad[N];
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(isbad, 0, sizeof isbad);
    memset(totson, 0, sizeof isbad);
    memset(f, 0, sizeof isbad);
    memset(dep, 0, sizeof isbad);
    n = d = 0;
    scanf("%d%d", &n, &d);
    int mind = 0, maxd = n * (n - 1) / 2;
    for (int i = 2; i <= n; ++i) {
      isbad[i] = 0;
      for (int j = 30; j >= 0; --j) {
        if ((1 << j) <= i) {
          mind += j;
          break;
        }
      }
    }
    if (d < mind || d > maxd) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (int i = 2; i <= n; ++i) {
      f[i] = i - 1;
      dep[i] = i - 1;
      totson[i - 1] = 1;
    }
    while (maxd > d) {
      int u = -1, tar = -1;
      for (int i = 1; i <= n; ++i) {
        if ((!totson[i]) && (!isbad[i]) && (u == -1 || dep[i] < dep[u])) {
          u = i;
        }
      }
      for (int i = 1; i <= n; ++i) {
        if (totson[i] < 2 && dep[i] == dep[u] - 2) {
          tar = i;
          break;
        }
      }
      if (tar == -1) {
        isbad[u] = 1;
      } else {
        totson[f[u]]--;
        totson[tar]++;
        dep[u]--;
        f[u] = tar;
        maxd--;
      }
    }
    for (int i = 2; i <= n; ++i) {
      printf("%d ", f[i]);
    }
    printf("\n");
  }
  return 0;
}
