#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
const int INF = 0x3f3f3f3f;
int Dep[maxn], sz[maxn];
int main() {
  int t;
  scanf("%d", &t);
  long long cnt = 1;
  for (int i = 0; i < 5000; ++i) {
    sz[i] = cnt;
    if (cnt >= INF)
      continue;
    else
      cnt *= 2;
  }
  while (t--) {
    int n, m, Md = 0;
    scanf("%d%d", &n, &m);
    memset(Dep, 0, sizeof(Dep));
    long long cnt = 0, sum = 0;
    for (int c = 1, d = 0;; c *= 2, d++) {
      Md = max(Md, d);
      if (cnt + c >= n) {
        Dep[d] = n - cnt;
        sum += Dep[d] * d;
        break;
      } else {
        Dep[d] = c;
        cnt += c;
        sum += Dep[d] * d;
      }
    }
    if (sum > m)
      printf("NO\n");
    else {
      bool flag = true;
      for (int i = sum + 1; i <= m; ++i) {
        bool ok = false;
        for (int j = Md; j >= 0; --j) {
          if ((Dep[j] > 1) && ((Dep[j] - 1) * 2 >= Dep[j + 1] + 1) &&
              (Dep[j + 1] + 1 <= sz[j + 1])) {
            Dep[j]--;
            Dep[j + 1]++;
            Md = max(Md, j + 1);
            ok = true;
            break;
          }
        }
        if (!ok) {
          flag = false;
          break;
        }
      }
      if (!flag)
        printf("NO\n");
      else {
        queue<int> fa;
        queue<int> son;
        fa.push(1);
        int idx = 1;
        printf("YES\n");
        for (int i = 1; i <= Md; ++i) {
          for (int j = 0; j < Dep[i]; ++j) {
            if (j && (j % 2) == 0) fa.pop();
            printf("%d ", fa.front());
            son.push(++idx);
          }
          fa = son;
          while (!son.empty()) son.pop();
        }
        printf("\n");
      }
    }
  }
  return 0;
}
