#include <bits/stdc++.h>
using i64 = long long;
int f(int n) {
return n * (n - 1) / 2 - (n - 1) / 2;
}
std::vector<int> construct(int n, int k) {
std::vector<int> p(n);
std::iota(p.begin(), p.end(), 0);
if (n <= 5) {
do {
std::vector a(n, std::vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i] > p[j]) {
a[i][j] = 1;
}
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = i + 1; j < n; j++) {
a[i][j] += a[i + 1][j];
}
}
for (int i = n - 1; i >= 0; i--) {
for (int j = i + 1; j < n; j++) {
a[i][j] += a[i][j - 1];
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
cnt += (a[i][j] % 2);
}
}
if (cnt == k) {
return p;
}
} while (std::next_permutation(p.begin(), p.end()));
return {};
}
if (k > f(n)) {
return {};
}
if (k == 0) {
return p;
}
if (k <= n - 2) {
p[k - 1] = k + 1;
p[k] = k - 1;
p[k + 1] = k;
return p;
}
if (k <= f(n - 2) + n - 1) {
auto q = construct(n - 2, k - (n - 1));
q.push_back(n - 1);
q.push_back(n - 2);
return q;
}
if (k == f(n)) {
for (int i = 0; i < n; i += 2) {
p[i] = i + 3;
}
for (int i = 1; i < n; i += 2) {
p[i] = i - 1;
}
std::vector<int> q(n);
std::iota(q.begin(), q.end(), 0);
std::sort(q.begin(), q.end(), [&](int i, int j) {
return p[i] < p[j];
});
for (int i = 0; i < n; i++) {
p[q[i]] = i;
}
return p;
}
p = construct(n - 2, f(n - 2));
std::vector a(n - 2, std::vector<int>(n - 2));
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 2; j++) {
if (p[i] > p[j]) {
a[i][j] = 1;
}
}
}
for (int i = n - 2 - 1; i >= 0; i--) {
for (int j = i + 1; j < n - 2; j++) {
a[i][j] += a[i + 1][j];
}
}
for (int i = n - 2 - 1; i >= 0; i--) {
for (int j = i + 1; j < n - 2; j++) {
a[i][j] += a[i][j - 1];
}
}
for (int i = 0; i < n - 2; i++) {
p[i] = p[i] * 3 + 2;
}
int N = 3 * n;
std::vector<int> fl(N), pl(N), fr(N), pr(N);
for (int x = 0; x < N; x++) {
int v = 0, s = 0;
for (int i = 0; i < n - 2; i++) {
v += (x > p[i]);
s += (v + a[0][i]) % 2;
}
fl[x] = s;
pl[x] = v;
}
for (int x = 0; x < N; x++) {
int v = 0, s = 0;
for (int i = n - 2 - 1; i >= 0; i--) {
v += (x < p[i]);
s += (v + a[i][n - 2 - 1]) % 2;
}
fr[x] = s;
pr[x] = v;
}
for (int x = 0; x < N; x++) {
for (int y = 0; y < N; y++) {
if (x % 3 == 2 || y % 3 == 2 || x == y) {
continue;
}
int cnt = f(n - 2) + fl[x] + fr[y] + (a[0][n - 2 - 1] + pl[x] + pr[y] + (x > y)) % 2;
if (cnt == k) {
p.insert(p.begin(), x);
p.push_back(y);
std::vector<int> q(n);
std::iota(q.begin(), q.end(), 0);
std::sort(q.begin(), q.end(), [&](int i, int j) {
return p[i] < p[j];
});
for (int i = 0; i < n; i++) {
p[q[i]] = i;
}
return p;
}
}
}
return {};
}
void solve() {
int n, k;
std::cin >> n >> k;
auto p = construct(n, k);
if (p.empty()) {
std::cout << "NO\n";
} else {
std::cout << "YES\n";
for (int i = 0; i < n; i++) {
std::cout << p[i] + 1 << " \n"[i == n - 1];
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}