Define the beauty of a permutation of numbers from $$$1$$$ to $$$n$$$ $$$(p_1, p_2, \dots, p_n)$$$ as number of pairs $$$(L, R)$$$ such that $$$1 \le L \le R \le n$$$ and numbers $$$p_L, p_{L+1}, \dots, p_R$$$ are consecutive $$$R-L+1$$$ numbers in some order. For example, the beauty of the permutation $$$(1, 2, 5, 3, 4)$$$ equals $$$9$$$, and segments, corresponding to pairs, are $$$[1]$$$, $$$[2]$$$, $$$[5]$$$, $$$[4]$$$, $$$[3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[5, 3, 4]$$$, $$$[1, 2, 5, 3, 4]$$$.Answer $$$q$$$ independent queries. In each query, you will be given integers $$$n$$$ and $$$k$$$. Determine if there exists a permutation of numbers from $$$1$$$ to $$$n$$$ with beauty equal to $$$k$$$, and if there exists, output one of them.

The first line contains a single integer $$$q$$$ ($$$1\le q \le 10\,000$$$) — the number of queries. Follow $$$q$$$ lines. Each line contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le k \le \frac{n(n+1)}{2}$$$) — the length of permutation and needed beauty respectively.

For a query output "NO", if such a permutation doesn't exist. Otherwise, output "YES", and in the next line output $$$n$$$ numbers — elements of permutation in the right order.

#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
using namespace std;
vi ca[105][105]; // i个数分成j段，总贡献为k，第一段大小 + 贡献 * 1024  *j = 1 最后更新*
int dp[105][6000]; // i个数总贡献为k，总段数 + 1024 * 合点
int cal(int x) {
	return x * (x - 1) / 2;
}
int r[105];
void work(int L, int R, int k, int bg, int tp) {
	if (L == R) {
		r[L] = bg;
		return;
	}

	int n = R - L + 1;
	int l = dp[n][k] % 1024;
	vi ns(l), res(l);
	int rtp = dp[n][k] & 1024;
	if (rtp) k -= cal(l);
	else k--;
	int fk = k;
	for (int j = 0; j < l; j++)
		ns[j] = ca[n][l - j][k] % 1024,
		res[j] = ca[n][l - j][k] / 1024,
		n -= ns[j],
		k -= res[j];
	/*
	cout << "W" << L << ' ' << R << ' ' << fk << ' ' << bg << ' ' << tp << ' ' << l << endl;
	for (int j = 0; j < l; j++)
		cout << ns[j] << ' ' << res[j] << endl;
	cout << endl;
	system("pause");
	*/
	if (rtp) {
		if (tp)
			for (int j = 0; j < l; j++)
				work(L, L + ns[j] - 1, res[j], bg, tp ^ 1),
				L += ns[j], bg += ns[j];
		else
			for (int j = l - 1; j >= 0; j--)
				work(R - ns[j] + 1, R, res[j], bg, tp ^ 1),
				R -= ns[j], bg += ns[j];
	}
	else {
		vi p(l), q(l);
		int k = l / 2;
		if (l % 2 == 0) {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
		}
		else {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
			p[2 * k] = 2 * k;
			swap(p[l - 1], p[l - 2]);
		}
		for (int i = 0; i < l; i++) {
			int nl = L;
			for (int j = 0; j < l; j++) {
				if (p[j] == i) {
					work(nl, nl + ns[j] - 1, res[j], bg, tp);
					bg += ns[j];
					break;
				}
				nl += ns[j];
			}
		}
	}
}
int main() {
	for (int i = 1; i < 101; i++) {
		for (int j = 1; j <= i; j++) {
			ca[i][j].resize(j + cal(i + 2 - j));
			if (i == 1 && j == 1) ca[1][1][1] = 1025, dp[1][1] = 1;
			else
				if (j >= 2)
					for (int l = i; l < ca[i][j].size(); l++)
						for (int k = 1; k <= i / j; k++) {
							if (ca[i][j][l]) break;
							int mx1 = cal(k + 1), mx2 = ca[i - k][j - 1].size() - 1;
							int du = max(k, l - mx2);
							for (int s = du; s <= mx1 && s <= l; s++)
								if (dp[k][s] && ca[i - k][j - 1][l - s]) {
									ca[i][j][l] = k + s * 1024;
									break;
								}
						}
		}
		for (int l = i; l <= cal(i + 1); l++) {
			for (int m = 2; m <= i; m++) {
				int ed = l - cal(m);
				if (ca[i][m].size() > ed && ca[i][m][ed]) {
					dp[i][l] = 1024 + m;
					break;
				}
			}
			for (int m = 4; m <= i; m++)
				if (ca[i][m].size() > l - 1 && ca[i][m][l - 1]) {
					dp[i][l] = m;
					break;
				}
			if (dp[i][l]) ca[i][1][l] = i + l * 1024;
		}
	}
	int t;
	int test = 0;
	if (test) t = 5050;
	else
		cin >> t;
	for (int i = 0; i < t; i++) {
		int n, k;
		if (test) n = 100, k = i + 1;
		else cin >> n >> k;
		if (!dp[n][k]) cout << "NO" << endl;
		else {
			cout << "YES" << endl;
			work(1, n, k, 1, 0);
			for (int j = 1; j <= n; j++)
				printf("%d ", r[j]);
			printf("\n");
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
const int MAXN = 105;
using lint = long long;

vector<int> gph[MAXN*2];
int typ[MAXN*2];
void apply_simple(vector<int> &v){
	reverse(all(v));
	int n = sz(v);
	if(n & 1) n--;
	int x = 0, y = n / 2;
	vector<int> ret;
	while(x < n / 2 || y < n){
		if(y < n) ret.push_back(v[y++]);
		if(x < n / 2) ret.push_back(v[x++]);
	}
	if(sz(v) != n){
		ret.insert(ret.begin() + n/2-1, v[n]);
	}
	v = ret;
}

void dfs(int x, int thr, vector<int> &v, int rev){
	if(x <= thr) v.push_back(x);
	else if(typ[x]) apply_simple(gph[x]);
	else{
		if(rev) reverse(all(gph[x]));
	}
	for(auto &i : gph[x]) dfs(i, thr, v, rev ^ 1);
}

vector<vector<int>> v;
vector<int> ans[MAXN][5111];
int dp[MAXN][5111];
int trk[MAXN][5111];
void solve(){
	for(int i=1; i<=100; i++){
		memset(dp, 0, sizeof(dp));
		dp[i][i] = 1;
		for(int j=i; j>=1; j--){
			for(int k=0; k<=i*(i+1)/2; k++){
				if(!dp[j][k]) continue;
				for(int l=2; l<=j; l++){
					if(!dp[j - l + 1][k + l * (l - 1) / 2]){
						dp[j - l + 1][k + l * (l - 1) / 2] = 1;
						trk[j - l + 1][k + l * (l - 1) / 2] = 2 * l;
					}
					if(l >= 4 && !dp[j - l + 1][k + 1]){
						dp[j - l + 1][k + 1] = 1;
						trk[j - l + 1][k + 1] = 2 * l + 1;
					}
				}
			}
		}
		for(int j=0; j<=5050; j++){
			if(sz(ans[i][j]) && dp[1][j]){
				vector<int> seq;
				int x = 1, y = j;
				while(x < i){
					int ans = trk[x][y];
					seq.push_back(ans);
					if(ans & 1){
						ans >>= 1;
						x += ans - 1;
						y -= 1;
					}
					else{
						ans >>= 1;
						x += ans - 1;
						y -= ans * (ans - 1) / 2;
					}
				}
				for(int i=0; i<2*MAXN; i++) gph[i].clear();
				reverse(all(seq));
				vector<int> tans(i);
				iota(all(tans), 1);
				int cnt = i;
				for(auto &i : seq){
					cnt++;
					for(int j=0; j<i/2; j++){
						gph[cnt].push_back(tans.back());
						tans.pop_back();
					}
					typ[cnt] = i & 1;
					tans.push_back(cnt);
				}
				vector<int> rans;
				dfs(cnt, i, rans, 0);
				for(auto &k : ans[i][j]) v[k] = rans;
			}
		}
	}
}

int main(){
	int cnt = 0;
	for(int i=1; i<=1; i++){
		int qr; scanf("%d",&qr);
		for(int j=0; j<qr; j++){
			int n, k;
			scanf("%d %d",&n,&k);
			ans[n][k].push_back(cnt++);
		}
	}
	v.resize(cnt);
	solve();
	for(int i=0; i<cnt; i++){
		if(sz(v[i])){
			puts("YES");
			for(auto &j : v[i]) printf("%d ", j);
			puts("");
		}
		else puts("NO");
	}
}

#include<bits/stdc++.h>
using namespace std;
int f[110][10010],g[110][10010],pre[110][10010][2],tmp[110],val[110][110];
bool check(int v)
{
	for(int i=1;i<=v;i++)
	{
		int mn=tmp[i],mx=tmp[i];
		for(int j=i+1;j<=v;j++)
		{
			mn=min(mn,tmp[j]);
			mx=max(mx,tmp[j]);
			if(mx-mn==j-i&&j-i+1<v)return 1;
		}
	}
	return 0;
}
void init(int x)
{
	for(int i=1;i<=x;i++)tmp[i]=i;
	while(check(x))random_shuffle(tmp+1,tmp+x+1);
	memcpy(val[x],tmp,sizeof(tmp));
}
inline int mul(int x)
{
	return x*(x-1)/2;
}
int q,n,k;
int main()
{
	scanf("%d",&q);
	for(int i=4;i<=100;i++)init(i);
	f[1][0]=1;
	for(int i=2;i<=100;i++)
	{
		for(int j=1;j<=mul(i);j++)
		{
			for(int k=1;k<=i;k++)
			{
				if(k>=4&&j>=1&&f[i-k+1][j-1])
				{
					pre[i][j][0]=i-k+1;
					f[i][j]=2;
				}
				else if(j>=mul(k)&&f[i-k+1][j-mul(k)])
				{
					pre[i][j][0]=i-k+1;
					f[i][j]=1;
				}
			}
		}
	}
	while(q--)
	{
		scanf("%d%d",&n,&k);
		if(k<n)
		{
			puts("NO");
			continue;
		}
		k-=n;
		if(!f[n][k])
		{
			puts("NO");
			continue;
		}
		else
		{
			puts("YES");
			int l=1,r=n,lst=1;
			while(n)
			{
				if(f[n][k]==1)
				{
					int siz=pre[n][k][0];
					if(!lst)
					{
						for(int i=1;i<=n-siz;i++)printf("%d ",i+l-1);
						l+=n-siz;
					}
					else
					{
						for(int i=1;i<=n-siz;i++)printf("%d ",r-i+1);
						r-=n-siz;
					}
					lst^=1;
					k-=mul(n-siz+1),n=siz;
				}
				else
				{
					int siz=pre[n][k][0];
					init(n-siz+1);
					int x=val[n-siz+1][n-siz+1];
					for(int i=1;i<=n-siz;i++)
					{
						if(val[n-siz+1][i]<x)printf("%d ",val[n-siz+1][i]+l-1);
						else printf("%d ",r-(n-siz+1-val[n-siz+1][i]));
					}
					l+=x-1;
					r=l+siz-1;
					k--;
					n=siz;
				}
			}
		}
		puts("");
	}
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend void pr(const modular& a) { pr(a.val); }
    friend void re(modular& a) { ll x; re(x); a = modular(x); }

    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bitset<5051> posi[101];

int calc(vi v) {
	int res = 0;
	F0R(i,sz(v)) {
		int mn = MOD, mx = -MOD;
		FOR(j,i,sz(v)) {
			ckmin(mn,v[j]); ckmax(mx,v[j]);
			if (mx-mn == j-i) res ++;
		}
	}
	return res;
}

vi base(int n) {
	vi v;
	for (int i = 2; i <= n; i += 2) v.pb(i);
	for (int i = 1; i <= n; i += 2) v.pb(i);
	if (n&1) swap(v[sz(v)-2],v[sz(v)-1]);
	return v;
}

bool mono(int a, int b, int c) {
	return (a < b) == (b < c);
}

vi gen(int n, int k) {
	assert(posi[n][k]);
	if (k == n*(n+1)/2) {
		vi v; FOR(i,1,n+1) v.pb(i);
		return v;
	}
	if (k == n+1) return base(n);
	FOR(a,2,n) {
		int b = n+1-a;
		F0R(A,k+2) {
			int B = k+1-A;
			if (!(posi[a][A] && posi[b][B])) continue;
			vi p = gen(a,A), q = gen(b,B);
			trav(t,q) t += p[0]-1;
			trav(t,p) if (t > p[0]) t += sz(q)-1;
			if (!mono(q.back(),q[0],p[1])) reverse(all(q));
			q.insert(q.end(),p.begin()+1,p.end());
			/*if (calc(q) != k) {
				ps("HUH",n,k,q); exit(0);
			}*/
			// assert(calc(q) == k);
			return q;
		}
	}
	exit(5);
	// ps("HUH",n,k);
	// exit(0);
}

void solve() {
	int n,k; re(n,k);
	if (!posi[n][k]) {
		ps("NO");
		return;
	}
	ps("YES");
	vi v = gen(n,k); assert(calc(v) == k);
	trav(t,v) pr(t,' ');
	ps();
}

int main() {
    setIO();
    FOR(i,1,101) {
    	if (i != 1 && i != 3) posi[i][i+1] = 1;
    	posi[i][i*(i+1)/2] = 1;
    }
    FOR(a,1,101) F0R(A,a*(a+1)/2+1) if (posi[a][A])
    	FOR(b,2,a+1) if (a+b-1 <= 100)
    		posi[a+b-1] |= posi[b]<<(A-1);
    int q; re(q);
    F0R(i,q) solve();
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 105;

int f[N][N * N], g[N][N * N], ans[N];
int q, n, k;

int main() {
    f[1][1] = 233;
    for (int i = 1; i <= 100; i++) {
        for (int j = 0; j <= 5050; j++) {
            if (!f[i][j]) continue;
            for (int k = 2; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k * (k + 1) / 2 - 1]) {
                    f[i + k - 1][j + k * (k + 1) / 2 - 1] = k;
                    g[i + k - 1][j + k * (k + 1) / 2 - 1] = 1;
                }
            }
            for (int k = 4; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k]) {
                    f[i + k - 1][j + k] = k;
                    g[i + k - 1][j + k] = 2;
                }
            }
        }
    }
    read(q);
    while (q--) {
        read(n); read(k); int tmp = n;
        if (n == 1 && k == 1) {
            printf("YES\n1\n");
            continue;
        }
        // printf("! %d %d\n", f[n][k], g[n][k]);
        if (!f[n][k]) {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
        vector <pii> seq;
        while (n != 1 || k != 1) {
            seq.push_back(make_pair(f[n][k], g[n][k]));
            if (g[n][k] == 1) {
                int tmp = f[n][k];
                k -= (tmp * (tmp + 1) / 2 - 1);
                n -= (tmp - 1);
            } else {
                int tmp = f[n][k];
                k -= tmp;
                n -= (tmp - 1);
            }
        }
        int l = 1, r = tmp, pos = 0, opt = 0;
        for (int i = 0; i < (int)seq.size(); i++) {
            if (seq[i].second == 1) {
                if (opt == 0) {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 1); opt ^= 1;
                } else {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = r - j + 1;
                    r -= (seq[i].first - 1); opt ^= 1;
                }
            } else {
                if (seq[i].first % 2 == 0) {
                    for (int j = 2; j <= seq[i].first - 2; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r;
                    for (int j = 1; j <= seq[i].first - 3; j += 2) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 2); --r;
                } else {
                    for (int j = 2; j <= seq[i].first - 3; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r - 1;
                    for (int j = 1; j <= seq[i].first - 4; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r;
                    l += (seq[i].first - 3); r -= 2;
                }
            }
        }
        ans[++pos] = l;
        for (int i = 1; i <= tmp; i++) print(ans[i], i == tmp ? '\n' : ' ');
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int kMaxN = 110;

bool can_reach[kMaxN][kMaxN * kMaxN];
bool is_ordered[kMaxN][kMaxN * kMaxN];
int num_children[kMaxN][kMaxN * kMaxN];

void Preproc() {
	can_reach[1][1] = true;
	for (int len = 1; len < kMaxN; ++len) {
		for (int nintvs = 1; nintvs <= len * len; ++nintvs) {
			if (!can_reach[len][nintvs]) {
				continue;
			}

			// Ordered nodes; there must be at least two children.
			for (int k = 2; len + k <= kMaxN; ++k) {
				const int new_len = len + k - 1;
				const int new_nintvs = nintvs + k * (k + 1) / 2 - 1;
				can_reach[new_len][new_nintvs] = true;
				is_ordered[new_len][new_nintvs] = true;
				num_children[new_len][new_nintvs] = k;
			}

			// Unordered nodes; at least four children.
			for (int k = 4; len + k <= kMaxN; ++k) {
				const int new_len = len + k - 1;
				const int new_nintvs = nintvs + k;
				can_reach[new_len][new_nintvs] = true;
				is_ordered[new_len][new_nintvs] = false;
				num_children[new_len][new_nintvs] = k;
			}
		}
	}
}

// Build a Divide-Combine Tree given the length of the permutation an num of intervals.
// Then, run a DFS on it in order to recover the permutation.
void Construct(int len, int nintvs) {
	vector<int> roots(len);
	const int init_len = len;
	iota(roots.begin(), roots.end(), 0);

	// Is the node an ordered node?
	vector<bool> node_ordered(len);

	// Children of the node, in yet undetermined order.
	vector<vector<int>> node_children(len);

	while (len > 1) {
		assert(can_reach[len][nintvs]);
		const int k = num_children[len][nintvs];
		const int new_root = node_children.size();
		vector<int> children(roots.end() - k, roots.end());
		roots.erase(roots.end() - k, roots.end());
		node_children.push_back(children);
		roots.push_back(new_root);

		if (is_ordered[len][nintvs]) {
			node_ordered.push_back(true);
			len -= (k - 1);
			nintvs -= k * (k + 1) / 2 - 1;
		} else {
			node_ordered.push_back(false);
			len -= (k - 1);
			nintvs -= k;
		}
	}

	vector<int> answer;

	// The [ordered_inc] argument here is negated in each recursive call
	//   in order to disallow putting increasing nodes as children
	//   of increasing nodes, and decreasing nodes as children of decreasing
	//   nodes.
	function<void(int, bool)> Dfs = [&](int v, bool ordered_inc) {
		if (v < init_len) {
			answer.push_back(v + 1);
		} else if (node_ordered[v]) {
			if (ordered_inc) {
				// Case 1: increasing node.
				for (int child : node_children[v]) {
					Dfs(child, !ordered_inc);
				}
			} else {
				// Case 2: decreasing node.
				const int sz = node_children[v].size();
				for (int i = sz - 1; i >= 0; --i) {
					Dfs(node_children[v][i], !ordered_inc);
				}
			}
		} else {
			// Case 3: unordered node. Put the children in a specific order in order
			//   to avoid any additional intervals.
			const int sz = node_children[v].size();
			vector<int> order;
			for (int start : {1, 0}) {
				for (int i = start; i < sz; i += 2) {
					order.push_back(i);
				}
			}
			if (sz % 2 == 1) {
				swap(order[sz - 2], order[sz - 1]);
			}
			for (int i : order) {
				Dfs(node_children[v][i], !ordered_inc);
			}
		}
	};

	Dfs(roots[0], true);

	for (int v : answer) {
		cout << v << " ";
	}
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	Preproc();

	int q;
	cin >> q;

	while (q--) {
		int n, k;
		cin >> n >> k;

		if (!can_reach[n][k]) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			Construct(n, k);
		}
	}
}

//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
	//~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef LOCAL
mt19937 rng(unsigned(69));
#else
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
#define rand rng

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

const int kMaxN = 110;

bool can_reach[kMaxN][kMaxN * kMaxN];
bool is_ordered[kMaxN][kMaxN * kMaxN];
int num_children[kMaxN][kMaxN * kMaxN];

void Preproc() {
	can_reach[1][1] = true;
	for (int len = 1; len < kMaxN; ++len) {
		for (int nintvs = 1; nintvs <= len * len; ++nintvs) {
			if (!can_reach[len][nintvs]) {
				continue;
			}

			// ordered nodes; there must be at least two children
			for (int k = 2; len + k <= kMaxN; ++k) {
				const int new_len = len + k - 1;
				const int new_nintvs = nintvs + k * (k + 1) / 2 - 1;
				can_reach[new_len][new_nintvs] = true;
				is_ordered[new_len][new_nintvs] = true;
				num_children[new_len][new_nintvs] = k;
			}

			// unordered nodes; at least four children
			for (int k = 4; len + k <= kMaxN; ++k) {
				const int new_len = len + k - 1;
				const int new_nintvs = nintvs + k;
				can_reach[new_len][new_nintvs] = true;
				is_ordered[new_len][new_nintvs] = false;
				num_children[new_len][new_nintvs] = k;
			}
		}
	}
}

void Construct(int len, int nintvs) {
	vector<int> roots(len);
	const int init_len = len;
	iota(ALL(roots), 0);

	vector<bool> node_ordered(len);
	vector<vi> node_children(len);

	while (len > 1) {
		assert(can_reach[len][nintvs]);
		const int k = num_children[len][nintvs];
		const int new_root = SZ(node_children);
		vi children(roots.end() - k, roots.end());
		roots.erase(roots.end() - k, roots.end());
		node_children.push_back(children);
		roots.push_back(new_root);

		if (is_ordered[len][nintvs]) {
			node_ordered.push_back(true);
			len -= (k - 1);
			nintvs -= k * (k + 1) / 2 - 1;
		} else {
			node_ordered.push_back(false);
			len -= (k - 1);
			nintvs -= k;
		}
	}

	debug() << imie(node_children);
	debug() << imie(node_ordered);

	assert(len == 1 && nintvs == 1);
	assert(SZ(roots) == 1);

	vi answer;

	function<void(int, bool)> Dfs = [&](int v, bool ordered_inc) {
		if (v < init_len) {
			answer.push_back(v + 1);
		} else if (node_ordered[v]) {
			if (ordered_inc) {
				for (int child : node_children[v]) {
					Dfs(child, !ordered_inc);
				}
			} else {
				const int sz = SZ(node_children[v]);
				for (int i = sz - 1; i >= 0; --i) {
					Dfs(node_children[v][i], !ordered_inc);
				}
			}
		} else {
			const int sz = SZ(node_children[v]);
			vi order;
			for (int start : {1, 0}) {
				for (int i = start; i < sz; i += 2) {
					order.push_back(i);
				}
			}
			if (sz % 2 == 1) {
				swap(order[sz - 2], order[sz - 1]);
			}
			for (int i : order) {
				Dfs(node_children[v][i], !ordered_inc);
			}
		}
	};

	Dfs(roots[0], true);

	for (int v : answer) {
		cout << v << " ";
	}
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

	Preproc();

	int q;
	cin >> q;

	while (q--) {
		int n, k;
		cin >> n >> k;

		if (!can_reach[n][k]) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			Construct(n, k);
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
const int MAX_N=105;
vector<int> ans[MAX_N][MAX_N*MAX_N];
vector<pair<int,int>> que;
void bfs(int p){
    if(p==que.size()){
        return;
    }
    auto [a1,b1]=que[p];
    for(int i=1;i<=p;++i){
        auto [a2,b2]=que[i];
        int a3=a1+a2-1;
        int b3=b1+b2-1;
        if(a3<=100&&ans[a3][b3].empty()){
            for(int x:ans[a2][b2]){
                ans[a3][b3].push_back(ans[a1][b1].front()+x-1);
            }
            for(int x:ans[a1][b1]){
                if(x!=ans[a1][b1].front()){
                    ans[a3][b3].push_back(x<ans[a1][b1].front()?x:x+a2);
                }
            }
            int x=min(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            int y=max(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            if(ans[a3][b3].front()<x||ans[a3][b3].front()>y){
                reverse(ans[a3][b3].begin(),ans[a3][b3].begin()+a2);
            }
            que.emplace_back(a3,b3);
        }
    }
    bfs(p+1);
}
int main(){
    for(int i=1;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i*(i+1)/2].push_back(j);
        }
    }
    for(int i=4;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i+1].push_back((j&1)?(j+i+1)/2:j/2);
        }
        if(i&1){
            swap(ans[i][i+1][i-3],ans[i][i+1][i-1]);
        }
    }
    for(int a=2;a<=100;++a){
        for(int b=a+1;b<=a*(a+1)/2;++b){
            if(ans[a][b].empty()){
                bool ok=false;
                for(int a1=4;a1<=a&&!ok;++a1){
                    int b1=a1+1;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2-1);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2);
                        }
                        ok=true;
                    }
                }
                for(int a1=2;a1<=a&&a1*(a1+1)/2<=b&&!ok;++a1){
                    int b1=a1*(a1+1)/2;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2-1);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2);
                        }
                        ok=true;
                    }
                }
            }
        }
    }
    int T;
    cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        if(ans[a][b].empty()){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            for(int x:ans[a][b]){
                cout<<x<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}

// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define len(a) int(a.size())
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout)
using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }

typedef long long base;
typedef pair<int, int> point;
typedef complex<double> comp;

const int N = 101;
const int T = 5;

int n;
bool used[N * N];
pair<point, point> how[N * N];

vector<int> can[N];
vector<pair<point, point>> way[N];
vector<int> answer[T][T * T];

void init_small() {
	for (int i = 1; i < T; ++i) {
		vector<int> res;
		for (int j = 1; j <= i; ++j) res.pb(j);
		do {
			int cnt = 0;
			for (int L = 0; L < i; ++L) {
				for (int R = L + 1; R <= i; ++R) {
					int minx = 1e9, maxx = -1e9;
					for (int M = L; M < R; ++M) {
						chkmax(maxx, res[M]);
						chkmin(minx, res[M]);
					}
					if (maxx - minx + 1 == R - L) {
						++cnt;
					}
				}
			}
			answer[i][cnt] = res;
		} while (next_permutation(res.begin(), res.end()));
		for (int j = 0; j <= (i + 1) * i / 2; ++j) {
			if (answer[i][j].size()) {
				can[i].pb(j);
			}
		}
	}
}

void init_big() {
	for (int a = T; a < N; ++a) {
		memset(used, 0, sizeof(used));
		for (int b = 2; b <= a + 1 - b; ++b) {
			int c = a + 1 - b;
			for (int wb : can[b]) {
				for (int wc : can[c]) {
					used[wb + wc - 1] = true;
					how[wb + wc - 1] = {{b, wb}, {c, wc}};
				}
			}
		}
		can[a].pb(a + 1);
		way[a].pb({{-1, -1}, {-1, -1}});
		for (int i = a + 2; i < a * (a + 1) / 2; ++i) {
			if (used[i]) {
				can[a].pb(i);
				way[a].pb(how[i]);
			}
		}
		can[a].pb(a * (a + 1) / 2);
		way[a].pb({{-1, -1}, {-1, -1}});
	}
}

void get(int a, int b, vector<int> &ans) {
	if (a < T) {
		ans = answer[a][b];
		return;
	}
	int it = lower_bound(can[a].begin(), can[a].end(), b) - can[a].begin();
	if (can[a][it] != b) return;
	if (b == a * (a + 1) / 2) {
		ans.resize(a);
		for (int i = 0; i < a; ++i) {
			ans[i] = i + 1;
		}
		return;
	}
	if (b == a + 1) {
		for (int i = 2; i <= a; i += 2) {
			ans.pb(i);
		}
		ans.pb(1);
		if (a & 1) ans.pb(a);
		for (int i = 3; i < a; i += 2) {
			ans.pb(i);
		}
		return;
	}
	vector<int> L, R;
	get(way[a][it].x.x, way[a][it].x.y, L);
	get(way[a][it].y.x, way[a][it].y.y, R);
	ans.resize(a);
	for (int i = 0; i < L.size(); ++i) ans[i] = L[i] + R[0] - 1;
	for (int i = 1; i < R.size(); ++i) {
		ans[L.size() + i - 1] = R[i] + int(R[i] > R[0]) * (L.size() - 1);
	}
	if ((ans[0] < ans[L.size() - 1]) == (ans[L.size() - 1] < ans[L.size()])) {
		reverse(ans.begin(), ans.begin() + L.size());
	}
}

int main() {
    ios::sync_with_stdio(0);
    srand(time(0));
    init_small();
    init_big();
    int t;
    cin >> t;
    while (t--) {
    	vector<int> ans;
    	int a, b;
    	cin >> a >> b;
    	get(a, b, ans);
    	if (ans.size() == 0) {
    		cout << "NO\n";
    	} else {
    		cout << "YES\n";
    		cout << ans << '\n';
    	}
    }
}

// luogu-judger-enable-o2
#include<bits/stdc++.h>
template<class T>inline void read(T &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=x*10+c-'0',c=getchar();
    if(f)x=-x;
}
const int N=110;
int T,n,k,lst,last,cnt,use,f[N][N*N],g[N][N*N];
std::vector<int> vet,ans,tmp,ano,pre[N];
std::vector<std::pair<int,int>> que;
void insert(int x,int opt){
    if(opt==1)ano=pre[x];
    else{
        last^=1,ano.clear();
        if(last)for(int i=1;i<=x;i++)ano.push_back(i);
        else for(int i=x;i>=1;i--)ano.push_back(i);
    }
    if(ans.size()){
        int cnt=0;for(int i=1;i<x;i++)cnt+=ano[i]<ano[0];
        for(int i=0;i<ans.size();i++)tmp.push_back(ans[i]+cnt);
        for(int i=1;i<ano.size();i++)tmp.push_back(ano[i]<ano[0]?ano[i]:ano[i]+ans.size()-1);
        ans=tmp,tmp.clear();
    }else ans=ano;
}
int main(){
#ifdef memset0
    freopen("1.in","r",stdin);
#endif
    f[1][0]=-1;
    for(int i=1;i<=100;i++){
        for(int j=0;j<=i*(i-1)/2;j++)
            for(int k=2;k<=i;k++){
                if(k>=4&&f[i-k+1][j-1])f[i][j]=1,g[i][j]=k;
                if(j-k*(k-1)/2>=0&&f[i-k+1][j-k*(k-1)/2])f[i][j]=2,g[i][j]=k;
            }
    }
    for(int k=4;k<=100;k++){
        vet.clear();for(int i=1;i<=k;i++)vet.push_back(i);
        while(true){
            std::random_shuffle(vet.begin(),vet.end());
            bool flag=false;
            for(int i=0;i<vet.size()&&!flag;i++)
                for(int j=i+1;j<(i?vet.size():vet.size()-1);j++){                    int min=vet[j],max=vet[j];
                    for(int k=i;k<j;k++)min=std::min(min,vet[k]),max=std::max(max,vet[k]);
                    if(max-min==j-i){flag=true;break;}
                }
            if(!flag)break;
        }
        pre[k]=vet;
    }
    for(vet.clear(),read(T);T--;vet.clear(),ans.clear(),que.clear(),cnt=use=0){
        read(n),read(k),lst=k-n,cnt=n;
        if(n==1&&k==1){puts("YES\n1");continue;}
        // printf("n=%d lst=%d f=%d\n",n,lst,f[n][lst]);
        if(lst<0||!f[n][lst]){puts("NO");continue;}
        for(int x=n,y=lst,k;~f[x][y];k=g[x][y],(f[x][y]==1?(x-=k-1,y-=1):(x-=k-1,y-=k*(k-1)/2))){
            // printf("> %d %d : %d %d\n",x,y,f[x][y],g[x][y]);
            que.push_back(std::make_pair(g[x][y],f[x][y]));
        }
        std::reverse(que.begin(),que.end());
        for(auto it=que.begin();it!=que.end();it++)insert(it->first,it->second);
        puts("YES");
        for(int i=0;i<n;i++)printf("%d%c",ans[i]," \n"[i==n-1]);
    }
}

#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forr(i, a, b) for (int i = (int)(b); i >= (int)(a); --i)
#define sz(a) (int)((a).size())

using namespace std;

const int ooi = 2e9;
const long long ool = 1e18 + 5;
const int mod = 1e9 + 7;
const double PI = acos(-1);
const long double eps = 1e-9;

typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef long double lld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int mxn = 110;
const int mxk = mxn * mxn / 2;

vi simple[mxn];
vi dp[mxn][mxk];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    fore(n, 4, 100) {
        for (int i = 1; i < n; i += 2) simple[n].pb(i);
        simple[n].pb(0);
        if (n & 1) simple[n].pb(n - 1);
        for (int i = 2; i < n - 1; i += 2) simple[n].pb(i);
    }
    dp[1][1] = vi({0});

    fore(n, 2, 100) {
        fore(k, n + 1, n * (n + 1) / 2) {
            fore(s, 4, n) {
                if (sz(dp[n - (s - 1)][k - s])) {
                    for (int v : dp[n - (s - 1)][k - s]) {
                        dp[n][k].pb(v + simple[s][0]);
                    }
                    for1(z, s - 1) {
                        int val = simple[s][z];
                        if (val > simple[s][0]) val += (n - s);
                        dp[n][k].pb(val);
                    }
                    goto found;
                }
            }

            for (int l = 2; l <= n && l * (l + 1) / 2 <= k; l++) {
                if (sz(dp[n - (l - 1)][k - l * (l + 1) / 2 + 1])) {
                    dp[n][k] = dp[n - (l - 1)][k - l * (l + 1) / 2 + 1];
                    reverse(all(dp[n][k]));
                    while (sz(dp[n][k]) < n) {
                        dp[n][k].pb(sz(dp[n][k]));
                    }
                    goto found;
                }
            }
found:
            ;
        }
    }

    int t; cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        if (dp[n][k].empty()) {
            cout << "NO\n";
        }
        else {
            cout << "YES\n";
            forn(i, n) cout << dp[n][k][i] + 1 << ' ';
            cout << '\n';
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
int const N=100;
bool dp[N+1][N*N];
vector<int>g[N+1];
pair<int,int>bck[N+1][N*N];
void no()
{
	printf("NO\n");
}
vector<int> go(int n,int m)
{
	if(m==n+1)
	{
		vector<int>an(n);
		int t=1,i=0;
		while(t<n)an[i++]=t,t+=2;
		reverse(an.begin(),an.begin()+i);
		an[i++]=n;
		t=2;
		while(t<n)an[i++]=t,t+=2;
		return an;
	}
	if(m==n*(n+1)>>1)
	{
		vector<int>an(n);
		f(i,0,n)an[i]=i+1;
		return an;
	}
	int n1=bck[n][m].first,m1=bck[n][m].second;
	vector<int>a=go(n1,m1),b=go(n-n1+1,m-m1+1);
	f(i,0,a.size())a[i]+=b[0]-1;
	int t=a.size();
	a.insert(a.end(),b.begin()+1,b.end());
	f(i,t,a.size())if(a[i]>b[0])a[i]+=t-1;
	if(a[t]>a[t-1]&&a[t-1]>a[0]||a[t]<a[t-1]&&a[t-1]<a[0])reverse(a.begin(),a.begin()+t);
	return a;
}
void solve()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1)
	{
		printf("YES\n1\n");
		return;
	}
	if(!dp[n][m])return no();
	vector<int>an=go(n,m);
	printf("YES\n%d ",an[0]);
	f(i,1,n)printf("%d ",an[i]);
	printf("\n");
}
int main(void)
{
	f(i,2,N+1)
	{
		if(i!=3)dp[i][i+1]=true;
		int lm=i*(i+1)>>1;
		dp[i][lm]=true;
		f(j,i+1,lm+1)if(dp[i][j])g[i].push_back(j);
		f(j,2,i+1)if(i+j-1<=N)f(k,0,g[i].size())f(w,0,g[j].size())if(!dp[i+j-1][g[i][k]+g[j][w]-1])
		{
			dp[i+j-1][g[i][k]+g[j][w]-1]=true;
			bck[i+j-1][g[i][k]+g[j][w]-1]=make_pair(i,g[i][k]);
		}
	}
	int t;
	scanf("%d",&t);
	while(t--)solve();
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
bool exist[101][51 * 101];
int last[101][51 * 101];
bool order[101][51 * 101];
void permutation(int n, int k, int base, bool coutOrder) {
	int number = last[n][k];
	if (n == 1) {
		cout << base + 1;
		return;
	}
	if (coutOrder && order[n][k]) {
		for (int i = 1; i < number; i++) cout << base + i << " ";
		permutation(n + 1 - number, k + 1 - number * (number + 1) / 2, base + number - 1, !coutOrder);
	}
	else if (!coutOrder && order[n][k]) {
		permutation(n + 1 - number, k + 1 - number * (number + 1) / 2, base + number - 1, !coutOrder);
		for (int i = number - 1; i >= 1; i--) cout << " " << base + i;
	}
	else if (coutOrder && !order[n][k]) {
		if (n % 2 == 0) {
			for (int i = n - 1; i >= 1; i = i - 2) cout << base + i << " ";
			permutation(n + 1 - number, k - number, base + number - 1, !coutOrder);
			for (int i = n - 2; i >= 2; i = i - 2) cout << " " << base + i;
		}
		else {
			for (int i = n - 1; i >= 2; i = i - 2) cout << base + i << " ";
			permutation(n + 1 - number, k - number, base + number - 1, !coutOrder);
			for (int i = 1; i <= n - 2; i = i + 2) cout << " " << base + i;
		}
	}
	else if (!coutOrder && !order[n][k]) {
		if (n % 2 == 0) {
			for (int i = 2; i <= n - 2; i = i + 2) cout << base + i << " ";
			permutation(n + 1 - number, k - number, base + number - 1, !coutOrder);
			for (int i = 1; i <= n - 1; i = i + 2)cout << " " << base + i;
		}
		else {
			for (int i = n - 2; i >= 1; i = i - 2) cout << base + i << " ";
			permutation(n + 1 - number, k - number, base + number - 1, !coutOrder);
			for (int i = 2; i <= n - 1; i = i + 2) cout << " " << base + i;
		}
	}
}
int main()
{
	for (int i = 1; i <= 100; i++)
		for (int j = 1; j <= i * (i + 1) / 2; j++)
			exist[i][j] = false;
	for (int i = 1; i <= 100; i++) {
		exist[i][i*(i + 1) / 2] = true;
		last[i][i*(i + 1) / 2] = i;
		order[i][i*(i + 1) / 2] = true;
		if (i >= 4) { exist[i][i + 1] = true; last[i][i + 1] = i; order[i][i + 1] = false; }
		for (int j = i + 2; j < i * (i + 1) / 2; j++) {
			for (int k = 2; k <= i - 1; k++)
				if (j + 1 - k * (k + 1) / 2 > i + 1 - k && exist[i + 1 - k][j + 1 - k * (k + 1) / 2]) {
					exist[i][j] = true;
					last[i][j] = k;
					order[i][j] = true;
					break;
				}
			if (!exist[i][j])
				for (int k = 4; k <= i - 1; k++)
					if (j > i + 1 && exist[i + 1 - k][j - k]) {
						exist[i][j] = true;
						last[i][j] = k;
						order[i][j] = false;
						break;
					}
		}
	}
	int q, n, k;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		cin >> n >> k;
		if (exist[n][k]) cout << "YES" << endl; else cout << "NO" << endl;
		if (exist[n][k]) {
			permutation(n, k, 0, true);
			cout << endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

vector<int> razuzdana(int n) {
	if (n == 1)
		return {0};
	vector<int> a;
	for (int i=0; i<n/2; i++) {
		a.push_back(n/2+i);
		a.push_back(i);
	}
	if (n % 2) {
		a.insert(a.begin()+1, n-1);
	}
	reverse(a.begin(), a.end());
	return a;
}

struct hop {
	unsigned k : 16;
	unsigned x : 8;
	unsigned mv : 2;
};

hop d[101][5052][101];

void dp() {
	memset(d, 0x55, sizeof(d));

	d[1][1][1] = {0, 0, 0};
	d[2][3][2] = {1, 1, 1};
	d[2][3][0] = {1, 1, 3};
	d[3][5][0] = {0, 0, 0};
	d[3][6][3] = {3, 2, 1};

	for (int n=4; n<=100; n++) {
		auto v = razuzdana(n);
		d[n][n+1][0] = {0, 0, 0};
	}

	for (unsigned n=3; n<100; n++) {
		for (unsigned k=n+1; k<=n*(n+1)/2; k++) {
			for (unsigned x=0; x<=n; x++) {
				if (d[n][k][x].k == 0x5555)
					continue;
				// produzi sufiks
				d[n+1][k+x+2-(x==n)][x+1] = {k, x, 1};
				// zapocni novi sufiks
				d[n+1][k+2][1] = {k, x, 3};
			}
		}
	}
}

vector<int> rek(int n, int k, int x) {
	if (d[n][k][x].mv == 0)
		return razuzdana(n);
	else if (d[n][k][x].mv == 1) {
		auto v = rek(n-1, d[n][k][x].k, d[n][k][x].x);
		v.push_back(n-1);
		return v;
	} else {
		auto v = rek(n-1, d[n][k][x].k, d[n][k][x].x);
		for (int& x : v)
			x = n-2-x;
		v.push_back(n-1);
		return v;
	}
}

void resi(int n, int k) {
	for (int x=0; x<=n; x++) {
		if (d[n][k][x].k != 0x5555) {
			cout << "YES\n";
			auto a = rek(n, k, x);
			for (int x : a) {
				cout << x+1 << ' ';
			}
			cout << '\n';
			return;
		}
	}
	cout << "NO\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	dp();
	int q;
	cin >> q;
	while (q--) {
		int n, k;
		cin >> n >> k;
		resi(n, k);
	}

}

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MAXM = 5055;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
bool dp[MAXN][MAXM];
int main() {
	int n = 100, m = 5050; dp[1][1] = true;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++) {
		if (!dp[i][j]) continue;
		for (int k = 4; i + k - 1 <= n; k++)
			dp[i + k - 1][j + k] = true;
		for (int k = 2; i + k - 1 <= n; k++)
			dp[i + k - 1][j + k * (k + 1) / 2 - 1] = true;
	}
	int T; read(T);
	while (T--) {
		read(n), read(m);
		if (dp[n][m]) {
			puts("YES"); int cur = 2;
			deque <int> ans; ans.push_back(1);
			bool type = true;
			while (n != 1) {
				for (int k = 2; k <= n; k++)
					if (m - k * (k + 1) / 2 + 1 >= 1 && dp[n - k + 1][m - k * (k + 1) / 2 + 1]) {
						if (type) {
							for (int i = 2; i <= k; i++, n--)
								ans.push_back(cur++);
							type = false;
						} else {
							for (int i = 2; i <= k; i++, n--)
								ans.push_front(cur++);
							type = true;
						}
						m -= k * (k + 1) / 2 - 1;
						break;
					}
				for (int k = 4; k <= n; k++)
					if (m - k >= 1 && dp[n - k + 1][m - k]) {
						int bak = cur++;
						for (int i = 3; i <= k; i++, n--)
							if (i & 1) ans.push_back(cur++);
							else ans.push_front(cur++);
						if (k & 1) ans.push_back(bak);
						else ans.push_front(bak);
						n--, m -= k;
						break;
					}
			}
			while (!ans.empty()) {
				printf("%d ", ans.front());
				ans.pop_front();
			}
			printf("\n");
		} else puts("NO");
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 110
vector<int>f[N][N*N],bz[N];
int main(){
	for(int i=4;i<N;i++){
		for(int j=1;j<=i;j++)
			if(j%2==0)bz[i].push_back(j);
		for(int j=1;j<=i;j++)
			if(j&1)bz[i].push_back(j);
		if(i&1)swap(*--bz[i].end(),*--(--bz[i].end()));
	}
	f[1][1]={1};
	f[2][3]={1,2};
	for(int i=1;i<N;i++)
		for(int j=0;j<=i*(i+1)/2;j++)
			if(f[i][j].size()){
				for(int k=2;k+i-1<N;k++){
					auto &v=f[i+k-1][j+k*(k+1)/2-1];
					if(!v.size()){
						v=f[i][j];
						if(v.back()==v.size())reverse(v.begin(),v.end());
						while(v.size()<i+k-1)v.push_back(v.size()+1);
					}
				}
				for(int k=4;k+i-1<N;k++){
					auto &v=f[i+k-1][j+k];
					if(!v.size()){
						for(auto x:bz[k]){
							if(x==1){
								for(auto x:f[i][j])
									v.push_back(x);
							}
							else v.push_back(i+x-1);
						}
					}
				}
			}
	int q,n,k;
	cin>>q;
	while(q--){
		cin>>n>>k;
		if(!f[n][k].size())puts("NO");
		else{
			puts("YES");
			for(auto x:f[n][k])cout<<x<<' ';
			cout<<'\n';
		}
	}
}//wargerrtyryyr

#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 100;
vector <int> dp[N + 3][N * (N - 1) / 2 + 3], biao[N + 3];

int main(void) {
	biao[4] = {3, 1, 4, 2};
	for (int i = 5; i <= N; i++) {
		rep (j, i) if (~j & 1) biao[i].push_back(j);
		rep (j, i) if (j & 1) biao[i].push_back(j);
		if (i & 1) swap(*--biao[i].end(), *--(--biao[i].end()));
		// if (i == 5) for (auto t : biao[i]) cout << t << " " ;
	}
	// cout << "\n";
	dp[1][1] = {1}; dp[2][3] = {1, 2};
	for (int i = 1; i <= N; i++) {
		for (int has = 0; has <= i * (i + 1) / 2; has++)
			if (dp[i][has].size()) {
				for (int k = 2; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k * (k + 1) / 2 - 1];
					if (t.size()) continue;
					t = dp[i][has];
					if (t.back() == t.size()) reverse(t.begin(), t.end());
					while (t.size() < i + k - 1) t.push_back(t.size() + 1);
				}
				for (int k = 4; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k];
					if (t.size()) continue;
					for (auto p : biao[k])
						if (p == 1)
							for (auto s : dp[i][has]) t.push_back(s);
						else t.push_back(i + p - 1);
				}
				// cout << i << " " << has << " : ";
				// for (auto t : dp[i][has]) cout << t << " " ; cout <<"\n";
			}
	}
	int q;
	read(q);
	rep (i, q) {
		int n, k;
		read(n); read(k);
		auto &t = dp[n][k];
		if (!t.size()) cout << "NO\n";
		else {
			cout << "YES\n";
			for (auto s : t) cout << s << " ";
			cout << "\n";
		}
	}

}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); i ++)
using namespace std;

const int N = 100;
vector <int> dp[N + 3][N * (N - 1) / 2 + 3], biao[N + 3];

int main(void) {
	for (int i = 4; i <= N; i++) {
		rep (j, i) if (~j & 1) biao[i].push_back(j);
		rep (j, i) if (j & 1) biao[i].push_back(j);
		if (i & 1) swap(*--biao[i].end(), *--(--biao[i].end()));
	}
	dp[1][1] = {1}; dp[2][3] = {1, 2};
	for (int i = 1; i <= N; i++)
		for (int has = 0; has <= i * (i + 1) / 2; has++)
			if (dp[i][has].size()) {
				for (int k = 2; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k * (k + 1) / 2 - 1];
					if (t.size()) continue;
					t = dp[i][has];
					if (t.back() == t.size()) reverse(t.begin(), t.end());
					while (t.size() < i + k - 1) t.push_back(t.size() + 1);
				}
				for (int k = 4; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k];
					if (t.size()) continue;
					for (auto p : biao[k])
						if (p == 1) for (auto s : dp[i][has]) t.push_back(s);
						else t.push_back(i + p - 1);
				}
			}
	int q;
	cin >> q;
	rep (i, q) {
		int n, k;
		cin >> n >> k;
		auto &t = dp[n][k];
		if (!t.size()) cout << "NO\n";
		else {
			cout << "YES\n";
			for (auto s : t) cout << s << " ";
			cout << "\n";
		}
	}

}

#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=105;
int a[N];
int dp[N][N*N];
void prework(){
	int n=N-5;
	dp[1][0]=1;
	For(i,1,n)
		For(j,0,i*(i-1)/2)
			if (dp[i][j]){
				For(k,1,n-i){
					dp[i+k][j+(k+1)*k/2]=i;
					if (k>=3)
						dp[i+k][j+1]=-i;
				}
			}
}
void Solve(){
	int n=read(),k=read();
	k-=n;
	if (k<0||!dp[n][k])
		return (void)puts("NO");
	For(i,1,n)
		a[i]=i;
	for (int i=n,j;i>1;i=j){
		j=dp[i][k];
		if (j>0){
			reverse(a+i,a+n+1);
			k-=(i-j)*(i-j+1)/2;
		}
		else {
			k--;
			j=abs(j);
			int len=n-i+1;
			int m=i-j+1;
			int Lp=j+m/2,Rp=Lp+len-1;
			For(p,Lp,Rp)
				a[p]=a[p-Lp+i];
			For(v,1,m-1)
				if (v&1)
					a[--Lp]=v+j-1;
				else
					a[++Rp]=v+j-1;
		}
	}
	puts("YES");
	For(i,1,n)
		printf("%d ",a[i]);
	puts("");
}
int main(){
	prework();
	int T=read();
	while (T--)
		Solve();
	return 0;
}

#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=105;
int a[N];
int dp[N][N*N];
void prework(){
	int n=N-5;
	dp[1][0]=1;
	For(i,1,n)
		For(j,0,i*(i-1)/2)
			if (dp[i][j]){
				For(k,1,n-i){
					dp[i+k][j+(k+1)*k/2]=i;
					if (k>=3)
						dp[i+k][j+1]=-i;
				}
			}
}
void Solve(){
	int n=read(),k=read();
	k-=n;
	if (k<0||!dp[n][k])
		return (void)puts("NO");
	For(i,1,n)
		a[i]=i;
	for (int i=n,j;i>1;i=j){
		j=dp[i][k];
		if (j>0){
			reverse(a+i,a+n+1);
			k-=(i-j)*(i-j+1)/2;
		}
		else {
			k--;
			j=abs(j);
			int len=n-i+1;
			int m=i-j+1;
			int Lp=j+m/2,Rp=Lp+len-1;
			For(p,Lp,Rp)
				a[p]=a[p-Lp+i];
			For(v,1,m-1)
				if (v&1)
					a[--Lp]=v+j-1;
				else
					a[++Rp]=v+j-1;
		}
//		outarr(a,1,n);
//		outval(j),outval(k);
	}
	puts("YES");
	For(i,1,n)
		printf("%d ",a[i]);
	puts("");
}
int main(){
	prework();
	int T=read();
	while (T--)
		Solve();
	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
using VI = vector<int>;
const int N = 101;
VI p[N][N*N/2];
VI q[N];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  for(int i=4; i<N; i++) {
    for(int j=1; j<i; j+=2) {
      q[i].pb(j);
    }
    for(int j=0; j<i-(i&1); j+=2) {
      q[i].pb(j);
      if((i&1) && !j) {
        q[i].pb(i-1);
      }
    }
  }
  p[1][1].pb(0);
  for(int n=2; n<N; n++) {
    for(int k=n+1; k<=n*(n+1)/2; k++) {
      for(int m=4; m<=n; m++) {
        if(p[n-m+1][k-m].empty()) {
          continue;
        }
        for(auto r:p[n-m+1][k-m]) {
          p[n][k].pb(r+1);
        }
        for(int i=1; i<m; i++) {
          p[n][k].pb(q[m][i]);
          if(q[m][i]>1) p[n][k].back()+=n-m;
        }
        break;
      }
      if(!p[n][k].empty()) {
        continue;
      }
      for(int m=2; m*(m+1)/2<=k; m++) {
        if(p[n-m+1][k-m*(m+1)/2+1].empty()) {
          continue;
        }
        p[n][k].resize(n);
        for(int i=0; i<n-m+1; i++) {
          p[n][k][i]=p[n-m+1][k-m*(m+1)/2+1][n-m-i];
        }
				for(int i=n-m+1; i<n; i++) {
				  p[n][k][i]=i;
				}
				break;
      }
    }
  }
  int q;
  scanf("%d", &q);
  for(int n, k; q--;) {
    scanf("%d %d", &n, &k);
    if(p[n][k].empty()) {
      puts("NO");
      continue;
    }
    puts("YES");
    for(auto r:p[n][k]) {
      printf("%d ", r+1);
    }
    puts("");
  }
  return 0;
}

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
using VI = vector<int>;
const int N = 101;
VI p[N][N*N/2];
VI q[N];
int main() {
  for(int i=4; i<N; i++) {
    for(int j=1; j<i; j+=2) {
      q[i].pb(j);
    }
    for(int j=0; j<i-(i&1); j+=2) {
      q[i].pb(j);
      if((i&1) && !j) {
        q[i].pb(i-1);
      }
    }
  }
  p[1][1].pb(0);
  for(int n=2; n<N; n++) {
    for(int k=n+1; k<=n*(n+1)/2; k++) {
      for(int m=4; m<=n; m++) {
        if(p[n-m+1][k-m].empty()) {
          continue;
        }
        for(auto r:p[n-m+1][k-m]) {
          p[n][k].pb(r+1);
        }
        for(int i=1; i<m; i++) {
          p[n][k].pb(q[m][i]);
          if(q[m][i]>1) p[n][k].back()+=n-m;
        }
        break;
      }
      if(!p[n][k].empty()) {
        continue;
      }
      for(int m=2; m*(m+1)/2<=k; m++) {
        if(p[n-m+1][k-m*(m+1)/2+1].empty()) {
          continue;
        }
        p[n][k].resize(n);
        for(int i=0; i<n-m+1; i++) {
          p[n][k][i]=p[n-m+1][k-m*(m+1)/2+1][n-m-i];
        }
        for(int i=n-m+1; i<n; i++) {
          p[n][k][i]=i;
        }
        break;
      }
    }
  }
  int q;
  scanf("%d", &q);
  for(int n, k; q--;) {
    scanf("%d %d", &n, &k);
    if(p[n][k].empty()) {
      puts("NO");
      continue;
    }
    puts("YES");
    for(auto r:p[n][k]) {
      printf("%d ", r+1);
    }
    puts("");
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 100;
bool dp[N + 1][N * N];
vector<int> g[N + 1];
pair<int, int> bck[N + 1][N * N];

void no() { printf("NO\n"); }

vector<int> go(int n, int m){
	if (m == n + 1){
		vector<int> an(n);
		int t = 1, i = 0;
		while (t < n)an[i++] = t, t += 2;
		reverse(an.begin(), an.begin() + i);
		an[i++] = n;
		t = 2;
		while (t < n)an[i++] = t, t += 2;
		return an;
	}
	if (m == n * (n + 1) >> 1){
		vector<int> an(n);
		f(i, 0, n)an[i] = i + 1;
		return an;
	}
	int n1 = bck[n][m].first, m1 = bck[n][m].second;
	vector<int> a = go(n1, m1), b = go(n - n1 + 1, m - m1 + 1);
	f(i, 0, a.size())a[i] += b[0] - 1;
	int t = a.size();
	a.insert(a.end(), b.begin() + 1, b.end());
	f(i, t, a.size())if (a[i] > b[0])a[i] += t - 1;
	if (a[t] > a[t - 1] && a[t - 1] > a[0] || a[t] < a[t - 1] && a[t - 1] < a[0])reverse(a.begin(), a.begin() + t);
	return a;
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	if (n == 1) {
		printf("YES\n1\n");
		return;
	}
	if (!dp[n][m])return no();
	vector<int> an = go(n, m);
	printf("YES\n%d", an[0]);
	f(i, 1, n)printf(" %d", an[i]);
	printf("\n");
}

int main(){
	f(i, 2, N + 1){
		if (i != 3)dp[i][i + 1] = true;
		int lm = i * (i + 1) >> 1;
		dp[i][lm] = true;
		f(j, i + 1, lm + 1)if (dp[i][j])g[i].push_back(j);
		f(j, 2, i + 1)if (i + j - 1 <= N)f(k, 0, g[i].size())f(w, 0, g[j].size())if (!dp[i + j - 1][g[i][k] + g[j][w] - 1]){
			dp[i + j - 1][g[i][k] + g[j][w] - 1] = true;
			bck[i + j - 1][g[i][k] + g[j][w] - 1] = make_pair(i, g[i][k]);
		}
	}
	int t;
	scanf("%d", &t);
	while (t--)solve();
}

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 110;
const int MAXK = MAXN * MAXN / 2;

vector<int> simple[MAXN];
vector<int> dp[MAXN][MAXK];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	for (int n = 4; n <= 100; n++) {
		// 1 3 5 0 2 4
		// 1 3 5 0 6 2 4
		for (int i = 1; i < n; i += 2) {
			simple[n].push_back(i);
		}
		simple[n].push_back(0);
		if (n % 2 == 1) {
			simple[n].push_back(n-1);
		}
		for (int i = 2; i < n-1; i += 2) {
			simple[n].push_back(i);
		}
	}

	dp[1][1] = vector<int>({0});

	for (int n = 2; n <= 100; n++) {
		for (int k = n+1; k <= n * (n+1) / 2; k++) {
			for (int s = 4; s <= n; s++) {
				if (!dp[n-(s-1)][k-s].empty()) {
					for (int v : dp[n-(s-1)][k-s]) {
						dp[n][k].push_back(v + simple[s][0]);
					}
					for (int z = 1; z < s; z++) {
						int val = simple[s][z];
						if (val > simple[s][0]) {
							val += n-s;
						}
						dp[n][k].push_back(val);
					}
					goto found;
				}
			}

			for (int l = 2; l <= n && l * (l+1) / 2 <= k; l++) {
				if (!dp[n - (l-1)][k - l * (l+1) / 2 + 1].empty()) {
					dp[n][k] = dp[n-(l-1)][k-l*(l+1)/2 + 1];
					reverse(dp[n][k].begin(), dp[n][k].end());
					while (int(dp[n][k].size()) < n) {
						dp[n][k].push_back(int(dp[n][k].size()));
					}
					goto found;
				}
			}
found:
			;
		}
	}

	int Q; cin >> Q;
	while (Q--) {
		int n, k; cin >> n >> k;
		if (dp[n][k].empty()) {
			cout << "NO\n";
		} else {
			cout << "YES\n";
			for (int i = 0; i < n; i++) {
				cout << dp[n][k][i]+1 << " \n"[i+1==n];
			}
		}
	}

	return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <complex>

#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3c3c3c3c;
const ll LINF = 1ll*INF*INF*2;

const int N = 101;
int n,m;

pii dp[101][5100];
pii Z={0,0};

void find(int x, int y, vector<int> &v) {
	if(x==1 && y==1) {v.push_back(1); return;}
	if(y==x*(x+1)/2) {
		for(int i=1; i<=x; i++) v.push_back(i);
		return;
	}
	if(y==x+1) {
		for(int i=2; i<=x; i+=2) v.push_back(i);
		v.push_back(1);
		int t=sz(v);
		for(int i=3; i<=x; i+=2) v.push_back(i);
		reverse(v.begin()+t, v.end());
		return;
	}
	vector<int> t2;
	int x1=dp[x][y].first;
	int y1=dp[x][y].second;
	int x2=x-x1+1;
	int y2=y-y1+1;
	find(x1, y1, v);
	find(x2, y2, t2);
	int P=t2[0];
	for(int i=0; i<sz(v); i++) v[i]+=P-1;
	for(int i=1; i<sz(t2); i++) {
		if(t2[i]<P) v.push_back(t2[i]);
		else v.push_back(t2[i]+x1-1);
	}
	if( (v[0]<v[x1-1] && v[0]<v[x1]) || (v[0]>v[x1-1] && v[0]>v[x1]) ) reverse(v.begin(), v.begin()+x1);
}
int main(void){
	dp[1][1]={1,1};
	for(int i=4; i<=100; i++) dp[i][i+1]={1,1};
	for(int i=2; i<=100; i++) dp[i][i*(i+1)/2]={1,1};
	for(int i=2; i<=100; i++) {
		for(int j=2; j<=i; j++) {
			if(i+j>101) break;
			for(int ii=i+1; ii<=i*(i+1)/2; ii++) {
				if(dp[i][ii]==Z) continue;
				for(int jj=j+1; jj<=j*(j+1)/2; jj++) {
					if(dp[j][jj]==Z) continue;
					dp[i+j-1][ii+jj-1]={i,ii};
				}
			}
		}
	}

	scanf("%d", &n);
	while(n--) {
		int x,y;
		scanf("%d%d", &x, &y);
		if(dp[x][y]==Z) {printf("NO\n"); continue;}

		printf("YES\n");
		vector<int> v;
		find(x,y,v);
		for(int e : v) printf("%d ", e); printf("\n");
	}
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100;
const int MAXWANT=MAXN*(MAXN+1)/2;

int prv[MAXN+1][MAXWANT+1];
int lst[MAXN+1][MAXWANT+1];

void precalc() {
	REPE(i,MAXN) REPE(j,MAXWANT) prv[i][j]=-2;
	prv[0][0]=-1;
	REPE(i,MAXN) REPE(j,MAXWANT) if(prv[i][j]!=-2) FORE(k,1,MAXN-i) {
		int ni=i+k,nj=j+k*(k+1)/2; if(prv[ni][nj]==-2) prv[ni][nj]=k;
	}
	REPE(i,MAXN) REPE(j,MAXWANT) {
		lst[i][j]=-2;
		if(i-1>=0&&prv[i-1][j]!=-2) lst[i][j]=1;
		if(lst[i][j]==-2&&j>=1) FORE(k,4,i) if(prv[i-k][j-1]!=-2) { lst[i][j]=k; break; }
	}
	//REPE(i,MAXN) REPE(j,MAXWANT) if(prv[i][j]!=-2) printf("prv %d %d: %d\n",i,j,prv[i][j]);
	//REPE(i,MAXN) REPE(j,MAXWANT) if(lst[i][j]!=-2) printf("lst %d %d: %d\n",i,j,lst[i][j]);
}

int n,want;
vector<int> ans;

bool solve() {
	if(want<n) return false;
	int x=n,y=want-n;
	if(lst[x][y]==-2) return false;

	int fin=lst[x][y];
	x-=fin; if(fin!=1) y-=1;
	vector<int> parts;
	while(x!=0||y!=0) { int k=prv[x][y]; parts.PB(k+1); x-=k; y-=k*(k+1)/2; }
	//printf("fin=%d parts=",fin); REPSZ(i,parts) { if(i!=0) printf(","); printf("%d",parts[i]); } puts("");

	int rem=0; REPSZ(i,parts) rem+=parts[i]-1;
	vector<int> pref,rsuff;
	REPSZ(i,parts) {
		int cnt=parts[i]; rem-=cnt-1;
		if(i%2==0) {
			for(int j=cnt;j>=2;--j) rsuff.PB(rem+j);
		} else {
			for(int j=cnt;j>=2;--j) pref.PB(rem+j);
		}
	}
	ans.clear(); REPSZ(i,pref) ans.PB(pref[i]); ans.PB(1); REPSZ(i,rsuff) ans.PB(rsuff[SZ(rsuff)-i-1]);
	//printf("ans:"); REPSZ(i,ans) printf(" %d",ans[i]); puts("");
	if(fin!=1) {
		REPSZ(i,ans) ++ans[i];
		for(int i=4;i<=fin;i+=2) ans.PB(n-(fin-i));
		ans.PB(1); for(int i=3;i<=fin;i+=2) ans.PB(n-(fin-i));
		if(fin%2==1) swap(ans[SZ(ans)-2],ans[SZ(ans)-1]);
	}
	//printf("ans:"); REPSZ(i,ans) printf(" %d",ans[i]); puts("");
	return true;
}

void run() {
	scanf("%d%d",&n,&want);
	if(!solve()) { printf("NO\n"); return; }
	printf("YES\n");
	REPSZ(i,ans) { if(i!=0) printf(" "); printf("%d",ans[i]); } puts("");
}

void verify() {
	assert(SZ(ans)==n); vector<bool> seen(n,false);
	int have=0;
	REP(i,n) {
		int x=ans[i]-1; assert(x>=0&&x<n&&!seen[x]); seen[x]=true;
		int mn=x,mx=x,len=1; ++have;
		FOR(j,i+1,n) {
			int y=ans[j]-1;
			mn=min(mn,y),mx=max(mx,y),++len; if(mx-mn+1==len) ++have;
		}
	}
	assert(have==want);
}

void stress() {
	for(n=1;n<=MAXN;++n) {
		for(want=1;want<=n*(n+1)/2;++want) {
			bool res=solve();
			if(res) verify();
		}
		printf("done %d\n",n);
	}
}

int main() {
	precalc();
	int ncase; scanf("%d",&ncase); FORE(i,1,ncase) run();
	//stress();
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;
const int PR = 3;

int gr[105][8192], vgr[105][8192];
int dp[105][8192], vdp[105][8192];

int perm[105][2][105];

int power(int x, int t)
{
	t %= MOD - 1;
	t += t < 0 ? MOD - 1 : 0;
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

void fft(int from[], int to[], int dir)
{
	int cur = 0;
	rep(i, 8192) {
		to[i] = from[cur];
		for(int j = 12; j >= 0; j --) {
			cur ^= 1 << j;
			if(cur >> j & 1) break;
		}
	}

	for(int d = 2; d <= 8192; d <<= 1) {
		int dr = power(PR, (MOD - 1) / d * dir);
		for(int i = 0; i < 8192; i += d) {
			int cr = 1;
			for(int j = i; j < i + (d >> 1); j ++) {
				int ev = to[j], od = 1LL * to[j + (d >> 1)] * cr % MOD;
				to[j] = (ev + od) % MOD;
				to[j + (d >> 1)] = (ev - od + MOD) % MOD;
				cr = 1LL * cr * dr % MOD;
			}
		}
	}

	if(dir == -1) {
		int invn = power(8192, -1);
		rep(i, 8192) to[i] = 1LL * to[i] * invn % MOD;
	}
}

int ret[105];
int main()
{
	for(int i = 2; i <= 100; i ++) {
		gr[i - 1][i * (i + 1) / 2 - 1] = 1;
		if(i >= 4) gr[i - 1][i] = 1;
	}
	rep1(i, 99) fft(gr[i], vgr[i], 1);

	for(int i = 2; i <= 100; i ++) {
		rep1(j, i) perm[i][1][j] = j;
		if(i >= 4) {
			rep1(j, i) perm[i][0][j] = j % 2 == 1 ? i / 2 + 1 + j / 2 : j / 2;
			if(i & 1) swap(perm[i][0][i - 2], perm[i][0][i]);
		}
	}

	dp[0][0] = 1;
	fft(dp[0], vdp[0], 1);

	rep1(i, 99) {
		rep1(j, i) rep(k, 8192) vdp[i][k] = (vdp[i][k] + 1LL * vgr[j][k] * vdp[i - j][k]) % MOD;
		fft(vdp[i], dp[i], -1);
		rep(k, 8192) dp[i][k] = dp[i][k] != 0;
		fft(dp[i], vdp[i], 1);
	}

	int T;
	scanf("%d", &T);
	while(T --) {
		int n, m;
		scanf("%d%d", &n, &m);
		if(dp[n - 1][m - 1]) {
			printf("YES\n");
			int cn = n - 1, cm = m - 1;
			int clen = 1;
			ret[1] = 1;
			while(cn > 0) {
				int curn = 0;
				for(curn = 1; (!gr[curn][curn + 1] || !dp[cn - curn][cm - curn - 1]) && !dp[cn - curn][cm - (curn + 1) * (curn + 2) / 2 + 1]; curn ++);
				bool fl = dp[cn - curn][cm - (curn + 1) * (curn + 2) / 2 + 1];
				rep1(i, clen) ret[i] += perm[curn + 1][fl][1] - 1;
				if(fl) reverse(ret + 1, ret + clen + 1);
				for(int i = clen + 1; i <= clen + curn; i ++)
				ret[i] = perm[curn + 1][fl][i - clen + 1] + (perm[curn + 1][fl][i - clen + 1] > perm[curn + 1][fl][1] ? clen - 1 : 0);
				clen += curn;
				cn -= curn;
				cm -= fl ? (curn + 1) * (curn + 2) / 2 - 1 : curn + 1;
			}
			rep1(i, n) printf("%d ", ret[i]); printf("\n");
		} else printf("NO\n");
	}
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int n=100;
vi f[n+1][n*(n+1)/2+1],g[n+1];

int main(){
	rep(i,4,n){
		rep(j,1,i) if(j%2==0) g[i].pb(j);
		rep(j,1,i) if(j%2==1) g[i].pb(j);
		if(i&1) swap(g[i][i-2],g[i][i-1]);
	}
	f[1][1]={1},f[2][3]={1,2};
	rep(i,1,n) rep(j,1,i*(i+1)/2){
		if(f[i][j].empty()) continue;
		rep(k,2,n-i+1){
			auto &r=f[i+k-1][j+k*(k+1)/2-1];
			if(!r.empty()) continue;
			r=f[i][j];
			if(r.back()==i) reverse(r.begin(),r.end());
			rep(p,1,k-1) r.pb(i+p);
		}
		rep(k,4,n-i+1){
			auto &r=f[i+k-1][j+k];
			if(!r.empty()) continue;
			for(auto p:g[k]){
				if(p==1) r.insert(r.end(),f[i][j].begin(),f[i][j].end());
				else r.pb(i+p-1);
			}
		}
	}
	int Q; read(Q);
	while(Q--){
		int n,k;
		read(n),read(k);
		if(f[n][k].empty()){
			puts("NO");
			continue;
		}
		puts("YES");
		for(auto x:f[n][k]) printf("%d ",x);
		puts("");
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=110;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,k,tt,ans[N];
bool f[N][N*N];

void solve(int l,int r,int k,bool op) {
	//cerr<<"solve:"<<l<<' '<<r<<' '<<k<<' '<<op<<'\n';
	if(l==r) {
		ans[l]=++tt;return;
	}
	int n=r-l+1;
	for(int i=4;n-i+1>0;i++)
		if(f[n-i+1][k-i]) {
			for(int j=r-i+2;j<=r;j+=2) ans[j]=++tt;
			solve(l,r-i+1,k-i,0);
			for(int j=r-i+3;j<=r;j+=2) ans[j]=++tt;
			if(i&1) swap(ans[r],ans[r-2]);
			return;
		}
	for(int i=2;n-i+1>0;i++)
		if(f[n-i+1][k-i*(i+1)/2+1]) {
			if(!op) {
				solve(l,r-i+1,k-i*(i+1)/2+1,1);
				for(int j=r-i+2;j<=r;j++) ans[j]=++tt;
			}
			else {
				solve(l+i-1,r,k-i*(i+1)/2+1,0);
				for(int j=l+i-2;j>=l;j--) ans[j]=++tt;
			}
			return;
		}
	assert(!"gzyakioi2020");
}

int main() {
	f[1][1]=1;
	for(int i=1;i<N;i++)
		for(int j=0;j<=i*(i+1)/2;j++)
			if(f[i][j]) {
				for(int k=4;i+k-1<N;k++) f[i+k-1][j+k]=1;
				for(int k=2;i+k-1<N;k++) f[i+k-1][j+k*(k+1)/2-1]=1;
			}
	//cerr<<"f[2][1]="<<f[2][1]<<'\n';
	int T=gi();
	while(T--) {
		cin>>n>>k;tt=0;
		if(!f[n][k]) puts("NO");
		else {
			puts("YES");
			solve(1,n,k,0);
			for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
			cout<<'\n';
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=105;
int zy[N][N*N/2];
bool dp[N][N*N/2];
deque<int> ans;
int id;
void dfs(int n,int k){
	if(n==1){
		ans.push_back(1); return;
	}else{
		if(zy[n][k]>0){
			dfs(n-zy[n][k]+1,k-zy[n][k]);
			int sz=ans.size();
			if(zy[n][k]&1){
				ans.push_front(zy[n][k]/2+sz);
				for(int i=1;i<zy[n][k]/2-1;i++){ans.push_back(sz+zy[n][k]/2+i);ans.push_back(sz+i); }
				ans.push_back(sz+zy[n][k]-1);
				ans.push_back(sz+zy[n][k]/2-1);
				ans.push_back(sz+zy[n][k]-2);
			}else{
				ans.push_front(zy[n][k]/2+sz);
				for(int i=1;i<zy[n][k]/2;i++){ans.push_back(sz+zy[n][k]/2+i);ans.push_back(sz+i); }
			}
		}else{
			dfs(n+zy[n][k]+1,k+zy[n][k]*(1-zy[n][k])/2+1);
			int sz=ans.size();
			if(id){
				For(i,1,-zy[n][k]-1)ans.push_back(sz+i);
			}else{
				For(i,1,-zy[n][k]-1)ans.push_front(sz+i);
			}
			id^=1;
		}
	}
}
int main(){
	dp[1][1]=1;
	For(i,2,100){
		For(j,i,i*(i+1)/2){
			For(k,2,i){
				if(k*(k+1)/2<=j&&dp[i-k+1][j-k*(k+1)/2+1]){
					dp[i][j]=1; zy[i][j]=-k; break;
				}
				if(k>=4&&dp[i-k+1][j-k]){
					dp[i][j]=1; zy[i][j]=k; break;
				}
			}
		}
	}
	int q=read();
	while(q--){
		int n=read(),k=read();
		if(!dp[n][k]){puts("NO");}
		else{
			id=1;
			dfs(n,k);
			puts("YES");
			while(ans.size()){
				wri(ans.front()); ans.pop_front();
			}puts("");
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define N 110
vector<int>f[N][N*N],bz[N];
int main(){
	for(int i=4;i<N;i++){
		for(int j=1;j<=i;j++)
			if(j%2==0)bz[i].push_back(j);
		for(int j=1;j<=i;j++)
			if(j&1)bz[i].push_back(j);
		if(i&1)swap(*--bz[i].end(),*--(--bz[i].end()));
	}
	f[1][1]={1};
	f[2][3]={1,2};
	for(int i=1;i<N;i++)
		for(int j=0;j<=i*(i+1)/2;j++)
			if(f[i][j].size()){
				for(int k=2;k+i-1<N;k++){
					auto &v=f[i+k-1][j+k*(k+1)/2-1];
					if(!v.size()){
						v=f[i][j];
						if(v.back()==v.size())reverse(v.begin(),v.end());
						while(v.size()<i+k-1)v.push_back(v.size()+1);
					}
				}
				for(int k=4;k+i-1<N;k++){
					auto &v=f[i+k-1][j+k];
					if(!v.size()){
						for(auto x:bz[k]){
							if(x==1){
								for(auto x:f[i][j])
									v.push_back(x);
							}
							else v.push_back(i+x-1);
						}
					}
				}
			}
	int q,n,k;
	cin>>q;
	while(q--){
		cin>>n>>k;
		if(!f[n][k].size())puts("NO");
		else{
			puts("YES");
			for(auto x:f[n][k])cout<<x<<' ';
			cout<<'\n';
		}
	}
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 105;
int dp[N][N*N],n,k,a[N];
void solve(int l, int r, int k, int vl, int vr, int cons){
	if(l==r){a[l]=vl;return;}
	if(dp[r-l+1][k]>0){
		int cnt=dp[r-l+1][k];
		if(cons){
			rep(i,l,l+cnt-2)a[i]=vr--;
			solve(l+cnt-1,r,k-cnt*(cnt+1)/2+1,vl,vr,0);
		}
		else{
			rep(i,l,l+cnt-2)a[i]=vl++;
			solve(l+cnt-1,r,k-cnt*(cnt+1)/2+1,vl,vr,1);
		}
		return;
	}
	int cnt=-dp[r-l+1][k],nk=k-cnt;
	if(cnt&1){
		int lim=vl+(r-cnt/2)-(l+cnt/2);
		rep(i,0,cnt/2-1)a[l+i]=lim+(i+1)*2,a[r-i]=lim+i*2+1;
		solve(l+cnt/2,r-cnt/2,nk,vl,vl+(r-cnt/2)-(l+cnt/2),0);
	}
	else{
		int lim=vl+(r-cnt/2+1)-(l+cnt/2);
		rep(i,0,cnt/2-1)a[l+i]=lim+i*2+1;
		rep(i,0,cnt/2-2)a[r-i]=vr-i*2-1;
		solve(l+cnt/2,r-cnt/2+1,nk,vl,vl+(r-cnt/2+1)-(l+cnt/2),0);
	}
}
int main() {
	dp[1][1]=1;
	rep(n,1,100)rep(k,1,n*(n+1)/2){
		for(int i=2;i<=n&&!dp[n][k];i++)if(k-i*(i+1)/2+1>=0&&dp[n-i+1][k-i*(i+1)/2+1]){
			dp[n][k]=i;
		}
		for(int i=4;i<=n&&i<=k&&!dp[n][k];i++)if(dp[n-i+1][k-i]){
			dp[n][k]=-i;
		}
	}
	int q;read(q);while(q--){
		read(n);read(k);
		if(!dp[n][k])puts("NO");
		else{
			puts("YES");
			solve(1,n,k,1,n,0);
			rep(i,1,n)printf("%d ",a[i]);puts("");
		}
	}
	return 0;
}

//
// Created by Feng Xinyu on 8/23/19.
//
//thought:
// if dp[n][k] exists and equal to c, then, there must exists m, l that permutation m can be transformed to n by an
// monotonic order of n - m + 1(k(k+1)/2) or an disorder of n - m + 1(k+1).
// even if dp[n][k] can be formed by several dp[a][b],dp[a1][b1].....
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair;
#define PI pair<int, int>
#define For(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define Rep(i, r, l) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second

const int N = 105;
int zy[N][N * N / 2];
bool dp[N][N * N / 2];
deque<int> ans;

void dfs(int n, int k) {
    if (n == 1) {
        ans.pb(1);
        return;
    } else {
        if (zy[n][k] > 0) {
            dfs(n - zy[n][k] + 1, k - zy[n][k]);
            int sz = ans.size();
            ans.pf(zy[n][k] / 2 + sz);
            if (zy[n][k] & 1) {
                For (i, 1, zy[n][k] / 2 - 2) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
                ans.pb(sz + zy[n][k] - 1);
                ans.pb(sz + zy[n][k] / 2 - 1);
                ans.pb(sz + zy[n][k] - 2);
            } else {
                For (i, 1, zy[n][k] / 2 - 1) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
            }
        } else {
            dfs(n + zy[n][k] + 1, k + zy[n][k] * (1 - zy[n][k]) / 2 + 1);
            int sz = ans.size();
            if (ans.front() > ans.back()) {
                For (i, 1, -zy[n][k] - 1) ans.pb(sz + i);
            } else {
                For (i, 1, -zy[n][k] - 1) ans.pf(sz + i);
            }
        }
    }
}

int main() {
    dp[1][1] = 1;
    For(i, 2, 100) {
        For(j, i + 1, i * (i + 1) / 2) {
            For(k, 2, i) {
                if (k * (k + 1) / 2 <= j && dp[i - (k - 1)][j - (k * (k + 1) / 2 - 1)]) {
                    dp[i][j] = 1; zy[i][j] = -k;
                }

                if (k >= 4 && dp[i - k + 1][j - k]) {
                    dp[i][j] = 1; zy[i][j] = k;
                }
            }
        }
    }

    int q, n, k;
    cin >> q;
    while (q--) {
        cin >> n >> k;
        if (!dp[n][k]) { puts("NO"); }
        else {
            dfs(n, k);
            puts("YES");
            while (ans.size()) {
                cout << ans.front() << ' ';
                ans.pop_front();
            }
            cout << endl;
        }
    }
    return 0;
}

//
// Created by Feng Xinyu on 8/23/19.
//
//thought:
// if dp[n][k] exists and equal to c, then, there must exists m, l that permutation m can be transformed to n by an
// monotonic order of n - m + 1(k(k+1)/2) or an disorder of n - m + 1(k+1).
// even if dp[n][k] can be formed by several dp[a][b],dp[a1][b1].....
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair;
#define PI pair<int, int>
#define For(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define Rep(i, r, l) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second

const int N = 105;
int zy[N][N * N / 2];
bool dp[N][N * N / 2];
deque<int> ans;

void dfs(int n, int k) {
    if (n == 1) {
        ans.pb(1);
        return;
    } else {
        if (zy[n][k] > 0) {
            dfs(n - zy[n][k] + 1, k - zy[n][k]);
            int sz = ans.size();
            ans.pf(zy[n][k] / 2 + sz);
            if (zy[n][k] & 1) {
                For (i, 1, zy[n][k] / 2 - 2) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
                ans.pb(sz + zy[n][k] - 1);
                ans.pb(sz + zy[n][k] / 2 - 1);
                ans.pb(sz + zy[n][k] - 2);
            } else {
                For (i, 1, zy[n][k] / 2 - 1) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
            }
        } else {
            dfs(n + zy[n][k] + 1, k + zy[n][k] * (1 - zy[n][k]) / 2 + 1);
            int sz = ans.size();
            if (ans.front() > ans.back()) {
                For (i, 1, -zy[n][k] - 1) ans.pb(sz + i);
            } else {
                For (i, 1, -zy[n][k] - 1) ans.pf(sz + i);
            }
        }
    }
}

int main() {
    dp[1][1] = 1;
    For(i, 2, 100) {
        For(j, i + 1, i * (i + 1) / 2) {
            Rep(k, i, 2) {
                if (k * (k + 1) / 2 <= j && dp[i - (k - 1)][j - (k * (k + 1) / 2 - 1)]) {
                    dp[i][j] = 1; zy[i][j] = -k; break;
                }

                if (k >= 4 && dp[i - k + 1][j - k]) {
                    dp[i][j] = 1; zy[i][j] = k; break;
                }
            }
        }
    }

    int q, n, k;
    cin >> q;
    while (q--) {
        cin >> n >> k;
        if (!dp[n][k]) { puts("NO"); }
        else {
            dfs(n, k);
            puts("YES");
            while (ans.size()) {
                cout << ans.front() << ' ';
                ans.pop_front();
            }
            cout << endl;
        }
    }
    return 0;
}

//
// Created by Feng Xinyu on 8/23/19.
//
//thought:
// if dp[n][k] exists and equal to c, then, there must exists m, l that permutation m can be transformed to n by an
// monotonic order of n - m + 1(k(k+1)/2) or an disorder of n - m + 1(k+1).
// even if dp[n][k] can be formed by several dp[a][b],dp[a1][b1].....
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair;
#define PI pair<int, int>
#define For(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define Rep(i, r, l) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second

const int N = 105;
int zy[N][N * N / 2];
bool dp[N][N * N / 2];
deque<int> ans;

void dfs(int n, int k) {
    if (n == 1) {
        ans.pb(1);
        return;
    } else {
        if (zy[n][k] > 0) {
            dfs(n - zy[n][k] + 1, k - zy[n][k]);
            int sz = ans.size();
            ans.pf(zy[n][k] / 2 + sz);
            if (zy[n][k] & 1) {
                For (i, 1, zy[n][k] / 2 - 2) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
                ans.pb(sz + zy[n][k] - 1);
                ans.pb(sz + zy[n][k] / 2 - 1);
                ans.pb(sz + zy[n][k] - 2);
            } else {
                For (i, 1, zy[n][k] / 2 - 1) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
            }
        } else {
            dfs(n + zy[n][k] + 1, k + zy[n][k] * (1 - zy[n][k]) / 2 + 1);
            int sz = ans.size();
            if (ans.front() > ans.back()) {
                For (i, 1, -zy[n][k] - 1) ans.pb(sz + i);
            } else {
                For (i, 1, -zy[n][k] - 1) ans.pf(sz + i);
            }
        }
    }
}

int main() {
    dp[1][1] = 1;
    For(i, 2, 100) {
        For(j, i + 1, i * (i + 1) / 2) {
            For(k, 2, i) {
                if (k * (k + 1) / 2 <= j && dp[i - (k - 1)][j - (k * (k + 1) / 2 - 1)]) {
                    dp[i][j] = 1; zy[i][j] = -k; break;
                }

                if (k >= 4 && dp[i - k + 1][j - k]) {
                    dp[i][j] = 1; zy[i][j] = k; break;
                }
            }
        }
    }

    int q, n, k;
    cin >> q;
    while (q--) {
        cin >> n >> k;
        if (!dp[n][k]) { puts("NO"); }
        else {
            dfs(n, k);
            puts("YES");
            while (ans.size()) {
                cout << ans.front() << ' ';
                ans.pop_front();
            }
            cout << endl;
        }
    }
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
#include <assert.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
pii h[105][105*107/2];
int q,N[SZ],K[SZ];
vector<int> aa[SZ];
vector<int> qry[105][105*107/2];
vector<int> ch[SZ];
int an=0,ty[SZ];
vector<int> op;
void dfs(int w,int d=0)
{
//	cerr<<w<<"!"<<ty[w]<<":";
//	for(auto c:ch[w]) cout<<c<<",";
//	cout<<"\n";
	if(!ch[w].size())
	{
		op.pb(w);
		return;
	}
	if(ty[w]==1)
	{
		vector<int> sb;
		int s=ch[w].size();
		for(int t=1;t<s;t+=2)
			sb.pb(ch[w][t]);
		sb.pb(ch[w][0]);
		for(int t=(s-1)-((s-1)&1);t>0;t-=2)
			sb.pb(ch[w][t]);
		for(auto r:sb) dfs(r,d^1);
	}
	else
	{
		vector<int> sb;
		for(auto r:ch[w]) sb.pb(r);
		if(d) reverse(sb.begin(),sb.end());
		for(auto r:sb) dfs(r,d^1);
	}
}
vector<int> cons(int n,int p)
{
//	cerr<<n<<","<<p<<"\n";
	an=n;
	vector<int> st;
	for(int i=1;i<=n;++i) ty[i]=0,ch[i].clear(),st.pb(i);
	int X=1,Y=p;
	while(X!=n)
	{
		pii g=h[X][Y];
		assert(g.fi!=-1);
		int y=g.se%2; g.se/=2;
		int c=g.fi-X+1;
		tie(X,Y)=g;
		++an; ty[an]=y; ch[an].clear();
		for(int j=1;j<=c;++j)
			ch[an].pb(st.back()),st.pop_back();
		reverse(ch[an].begin(),ch[an].end());
		st.pb(an);
	}
	assert(Y==n&&st.size()==1);
	op.clear();
	dfs(an);
	#ifdef LOCAL
	#warning "LOCAL ON"
	assert(op.size()==n);
	int sb=0;
	for(int i=0;i<n;++i)
	{
		vector<int> g;
		for(int j=i;j<n;++j)
		{
			g.pb(op[j]);
			sort(g.begin(),g.end());
			bool ok=1;
			for(int w=0;w<g.size();++w)
				ok&=g[w]==g[0]+w;
			if(ok) ++sb;
		}
	}
//	cerr<<sb<<"?\n";
	assert(sb==p);
	#endif
	return op;
}
int main()
{
	scanf("%d",&q);
	for(int i=1;i<=q;++i)
		scanf("%d%d",N+i,K+i),
		qry[N[i]][K[i]].pb(i);
	for(int n=1;n<=100;++n)
	{
	memset(h,-1,sizeof h);
	h[n][n]=pii(0,0);
	for(int i=n;i>=1;--i)
	{
		for(int j=n*(n+1)/2;j>=0;--j) if(~h[i][j].fi)
		{
			for(int c=2;c<=i;++c)
			{
				h[i-c+1][j+c*(c-1)/2]=pii(i,j*2);
				if(c>=4) h[i-c+1][j+1]=pii(i,j*2+1);
			}
		}
	}
	for(int j=n*(n+1)/2;j>=0;--j)
		if(h[1][j].fi!=-1&&qry[n][j].size())
		{
			auto u=cons(n,j);
			for(auto r:qry[n][j]) aa[r]=u;
		}
	}
	for(int i=1;i<=q;++i)
		if(aa[i].size())
		{
			puts("YES");
			for(auto x:aa[i])
				printf("%d ",x);
			puts("");
		}
		else
			puts("NO");
}

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define pii pair<int,int>
#define fir first
#define sec second
#define mk make_pair
#define pb push_back
#define ll long long
#define N 210
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,q,path[N][N*N],tp[N][N*N],a[N];
signed main()
{
	path[1][0]=-1;
	for(int i=2;i<=100;i++)
		for(int k=i;k<=i*(i+1)/2;k++)
		{
			for(int j=2;j<=i;j++)if(k>=j*(j+1)/2-1 && path[i-j+1][k-j*(j+1)/2+1])path[i][k]=j,tp[i][k]=1;
			for(int j=4;j<=i;j++)if(path[i-j+1][k-j])path[i][k]=j,tp[i][k]=2;
		}
	for(q=read();q--;)
	{
		n=read();int k=read()-1;
		if(!path[n][k]){puts("NO");continue;}
		puts("YES");
		int l=1,r=n,rev=0;
		for(int i;l<r;)
		{
			int w=path[n][k];
			if(tp[n][k]==1)
			{
				if(rev){for(i=r;i>=r-w+2;i--)printf("%d ",i);r=i;}
				else {for(i=l;i<=l+w-2;i++)printf("%d ",i);l=i;}
				rev^=1;k-=w*(w+1)/2-1;
			}
			else
			{
				int cnt=0;//¹¹Ôìµ¥ÅÅÁÐ
				for(i=l+1;i<=l+w-1;i+=2)a[++cnt]=i;
				for(i=l  ;i<=l+w-1;i+=2)a[++cnt]=i;
				if(w&1)a[w/2]=r-1,a[w-1]=r,r-=2,l+=w-3;
				else a[w/2]=r--,l+=w-2;
				for(int i=1;i<cnt;i++)printf("%d ",a[i]);
				k-=w;
			}
			n-=w-1;
		}
		printf("%d\n",l);
	}
	return 0;
}

#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4951];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=i*(i-1)/2; ++j)
			if(f[i][j]) {
				for(int l=2; i+l<=101; ++l) f[i+l-1][j+l*(l-1)/2]=l;
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=i*(i-1)/2; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(k<0) puts("NO"); else if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}

#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4951];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=4950; ++j)
			if(f[i][j])
				for(int l=2; i+l<=101; ++l) f[i+l-1][j+l*(l-1)/2]=l;
	for(int j=0; j<=4950; ++j)
		for(int i=1; i<=100; ++i)
			if(f[i][j]) {
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
				break;
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=4950; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(k<0) puts("NO"); else if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}

#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4951];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=4950; ++j)
			if(f[i][j]) {
				for(int l=2; i+l<=101; ++l) f[i+l-1][j+l*(l-1)/2]=l;
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=4950; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(k<0) puts("NO"); else if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 110, N = 100;
pair<int, int> p[maxn][maxn * maxn];
int ta[maxn], tb[maxn], cnt, tp[maxn], ans[maxn];
void calc(int a, int b) {
	int a1 = p[a][b].first, b1 = p[a][b].second, a2 = a + 1- a1, b2 = b + 1 - b1;
	if(a1 == a) {
		ta[++cnt] = a; tb[cnt] = b; return;
	}
	calc(a1, b1); calc(a2, b2);
}
void getp(int a, int b) {
	if(b == a * (a + 1) / 2) {
		rep(i, 1, a) tp[i] = i;
		return;
	}
	if(b == a + 1) {
		int num = 0;
		for(int i = 2; i <= a; i += 2) tp[++num] = i;
		tp[++num] = 1; num = a;
		for(int i = 3; i <= a; i += 2) tp[num--] = i;
		return;
	}
	tp[1] = 1;
}
int main() {
	p[1][1] = make_pair(1, 1);
	rep(a, 2, N) {
		if(a != 3) p[a][a + 1] = make_pair(a, a + 1);
		p[a][a * (a + 1) / 2] = make_pair(a, a * (a + 1) / 2);
		rep(a1, 2, a - 1) {
			int a2 = a + 1 - a1;
			rep(b1, a1 + 1, a1 * (a1 + 1) / 2) if(p[a1][b1].first)
				rep(b2, a2 + 1, a2 * (a2 + 1) / 2) if(p[a2][b2].first) {
					p[a][b1 + b2 - 1] = make_pair(a1, b1);
					//cout << a << ' ' << b1 + b2 - 1 << endl;
				}
		}
	}
	int Q; scanf("%d", &Q);
	while(Q--) {
		int a, b; scanf("%d%d", &a, &b);
		if(!p[a][b].first) { printf("NO\n"); continue; }
		printf("YES\n");
		cnt = 0;
		calc(a, b);
		int num = 0;
		rep(i, 1, cnt) {
			getp(ta[i], tb[i]);
			if(!num) rep(j, 1, ta[j]) ans[++num] = tp[j];
			else {
				if(ta[i] == 1) continue;
				int tmp = ans[num]; num--;
				rep(j, 1, num) if(ans[j] > tmp) ans[j] += ta[i] - 1;
				rep(j, 1, ta[i]) ans[++num] = tp[j] + tmp - 1;
				int mn = ans[num - ta[i]], mx = ans[num - ta[i] + 1];
				if(mn > mx) swap(mn, mx);
				if(ans[num] < mn || ans[num] > mx) reverse(ans + num - ta[i] + 1, ans + num + 1);
			}
		}
		rep(i, 1, a) printf("%d ", ans[i]);
		printf("\n");
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int N=105;
bool f[N][5555];
int S[N],n,nd,ans[N];
void init(){
	For(i,1,N-1) S[i]=i*(i+1)/2;
	f[0][0]=1;
	For(i,1,N-1) f[i][S[i]]=1;
	For(i,4,N-1) f[i][i+1]=1;
	For(i,1,N-1) For(j,i,S[i]) if (f[i][j]){
		For(k,2,N-i) f[i+k-1][j+S[k]-1]=1;
		For(k,4,N-i) f[i+k-1][j+k]=1;
	}
}
/*
3 1 4 2 5
*/
void construct(int l,int r,int n,int k,int op){
	//printf("con %d %d %d %d\n",l,r,n,k);
	if (k==n*(n+1)/2){
		if (op==0) For(i,l,r) ans[i]=++nd;
		else Rep(i,r,l) ans[i]=++nd;
		return;
	}
	if (k==n){
		for (int i=l+1;i<=r;i+=2) ans[i]=++nd;
		for (int i=l;i<=r;i+=2) ans[i]=++nd;
		if (n%2==1) swap(ans[r],ans[r-2]);
		return;
	}
	For(i,2,n)
		if (k-S[i]+1>0)
			if (f[n-i+1][k-S[i]+1]){
				if (op==0){
					construct(l,r-i+1,n-i+1,k-S[i]+1,1);
					For(j,r-i+2,r) ans[j]=++nd;
				}
				else{
					construct(l+i-1,r,n-i+1,k-S[i]+1,0);
					Rep(j,l+i-2,l) ans[j]=++nd;
				}
				return;
			}
	For(i,4,n)
		if (k-i>0)
			if (f[n-i+1][k-i]){
				for (int j=r-i+2;j<=r;j+=2) ans[j]=++nd;
				construct(l,r-i+1,n-i+1,k-i,0);
				for (int j=r-i+3;j<=r;j+=2) ans[j]=++nd;
				if (n&1) swap(ans[r-2],ans[r]);
				return;
			}
}
void solve(){
	int n,k; nd=0;
	scanf("%d%d",&n,&k);
	if (!f[n][k]) return puts("NO"),void(0);
	construct(1,n,n,k,0);
	puts("YES");
	For(i,1,n) printf("%d ",ans[i]);
	puts("");
}
int main(){
	init();
	int Q;
	scanf("%d",&Q);
	while (Q--) solve();
}

// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=111;

bool dp[maxn][maxn*maxn/2];
int pre[maxn][maxn*maxn/2],tp[maxn][maxn*maxn/2],q,n,k;

vector<int> all[maxn],ind[maxn];

vector<int> merge(const vector<int>&a,const vector<int>&b)
{
	vector<int> ret;
	int cur=b[0];
	for(auto v:a)ret.pb(v+cur-1);
	if((b[1]>b[0])==(ret[0]<ret[(int)ret.size()-1]))reverse(ret.begin(),ret.end());
	for(auto v:b)if(v<cur)ret.pb(v);else if(v>cur)ret.pb(v+(int)a.size()-1);
	return ret;
}

vector<int> calc(int n,int k)
{
	if(k==n*(n+1)/2)return all[n];
	else if(k==n+1)return ind[n];
	if(tp[n][k]==0)return merge(calc(n-pre[n][k]+1,k-pre[n][k]),ind[pre[n][k]]);
	else return merge(calc(n-pre[n][k]+1,k-pre[n][k]*(pre[n][k]+1)/2+1),all[pre[n][k]]);
}

void solve()
{
	get2(n,k);
	if(n==1)
	{
		puts("YES");
		puts("1");
		return;
	}
	if(dp[n][k])
	{
		puts("YES");
		vector<int> ans=calc(n,k);
		for(auto v:ans)printf("%d ",v);puts("");
	}
	else puts("NO");
}

int main()
{
	for(int i=2;i<=100;i++)
	{
		if(i>3)dp[i][i+1]=1;
		dp[i][i*(i+1)/2]=1;
		for(int j=i+1;j<=i*(i+1)/2;j++)if(dp[i][j])
		{
			for(int k=2;i+k-1<=100;k++)
			{
				dp[i+k-1][j+k*(k+1)/2-1]=1;
				pre[i+k-1][j+k*(k+1)/2-1]=k;
				tp[i+k-1][j+k*(k+1)/2-1]=1;
				if(k>3)
				{
					dp[i+k-1][j+k]=1;
					pre[i+k-1][j+k]=k;
					tp[i+k-1][j+k]=0;
				}
			}
		}
	}
	for(int i=1;i<=100;i++)
	{
		for(int j=1;j<=i;j++)all[i].pb(j);
		if(i<=3)continue;
		if(i%2==0)
		{
			for(int j=2;j<=i;j+=2)ind[i].pb(j);
			for(int j=1;j<=i;j+=2)ind[i].pb(j);
		}
		else
		{
			ind[i]=ind[i-1];
			ind[i].pop_back();
			ind[i].pb(i);
			ind[i].pb(i-2);
		}
	}
	get1(q);
	while(q--)solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,cc,ans[N],s[N],f[N][5555];
inline void init()
{
	for(int i=1;i<N;i++)s[i]=i*(i+1)/2;
	f[0][0]=1;
	for(int i=1;i<N;i++)f[i][s[i]]=1;
	for(int i=4;i<N;i++)f[i][i+1]=1;
	for(int i=1;i<N;i++)for(int j=i;j<=s[i];j++)if(f[i][j])
	{
		for(int k=2;k<=N-i;k++)f[i+k-1][j+s[k]-1]=1;
		for(int k=4;k<=N-i;k++)f[i+k-1][j+k]=1;
	}
}
void dfs(int l,int r,int n,int k,int op)
{
	if(k==n*(n+1)/2)
	{
		if(op==0)for(int i=l;i<=r;i++)ans[i]=++cc;
		else for(int i=r;i>=l;i--)ans[i]=++cc;return;
	}
	if(k==n+1)
	{
		for(int i=l+1;i<=r;i+=2)ans[i]=++cc;
		for(int i=l;i<=r;i+=2)ans[i]=++cc;
		if(n&1)swap(ans[r],ans[r-2]);return;
	}
	for(int i=2;i<=n;i++)if(k-s[i]+1>0&&f[n-i+1][k-s[i]+1])
	{
		if(!op)
		{
			dfs(l,r-i+1,n-i+1,k-s[i]+1,1);
			for(int j=r-i+2;j<=r;j++)ans[j]=++cc;
		}
		else
		{
			dfs(l+i-1,r,n-i+1,k-s[i]+1,0);
			for(int j=l+i-2;j>=l;j--)ans[j]=++cc;
		}
		return;
	}
	for(int i=4;i<=n;i++)if(k-i>0&&f[n-i+1][k-i])
	{
		for(int j=r-i+2;j<=r;j+=2)ans[j]=++cc;
		dfs(l,r-i+1,n-i+1,k-i,0);
		for(int j=r-i+3;j<=r;j+=2)ans[j]=++cc;
		if(n&1)swap(ans[r-2],ans[r]);
		return;
	}
}
void sol()
{
	int n,k;cc=0;scanf("%d%d",&n,&k);
	if(!f[n][k]){puts("NO");return;}
	dfs(1,n,n,k,0);puts("YES");
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);puts("");
}
int main(){init();int T;scanf("%d",&T);while(T--)sol();return 0;}

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,cc,ans[N],s[N],f[N][5555];
inline void init()
{
	for(int i=1;i<N;i++)s[i]=i*(i+1)/2;
	f[0][0]=1;
	for(int i=1;i<N;i++)f[i][s[i]]=1;
	for(int i=4;i<N;i++)f[i][i+1]=1;
	for(int i=1;i<N;i++)for(int j=i;j<=s[i];j++)if(f[i][j])
	{
		for(int k=2;k<=N-i;k++)f[i+k-1][j+s[k]-1]=1;
		for(int k=4;k<=N-i;k++)f[i+k-1][j+k]=1;
	}
}
void dfs(int l,int r,int n,int k,int op)
{
	if(k==n*(n+1)/2)
	{
		if(op==0)for(int i=l;i<=r;i++)ans[i]=++cc;
		else for(int i=r;i>=l;i--)ans[i]=++cc;return;
	}
	for(int i=2;i<=n;i++)if(k-s[i]+1>0&&f[n-i+1][k-s[i]+1])
	{
		if(!op)
		{
			dfs(l,r-i+1,n-i+1,k-s[i]+1,1);
			for(int j=r-i+2;j<=r;j++)ans[j]=++cc;
		}
		else
		{
			dfs(l+i-1,r,n-i+1,k-s[i]+1,0);
			for(int j=l+i-2;j>=l;j--)ans[j]=++cc;
		}
		return;
	}
	for(int i=4;i<=n;i++)if(k-i>0&&f[n-i+1][k-i])
	{
		for(int j=r-i+2;j<=r;j+=2)ans[j]=++cc;
		dfs(l,r-i+1,n-i+1,k-i,0);
		for(int j=r-i+3;j<=r;j+=2)ans[j]=++cc;
		if(i&1)swap(ans[r-2],ans[r]);
		return;
	}
}
void sol()
{
	int n,k;cc=0;scanf("%d%d",&n,&k);
	if(!f[n][k]){puts("NO");return;}
	dfs(1,n,n,k,0);puts("YES");
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);puts("");
}
int main(){init();int T;scanf("%d",&T);while(T--)sol();return 0;}

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,cc,ans[N],s[N],f[N][5555];
inline void init()
{
	for(int i=1;i<N;i++)s[i]=i*(i+1)/2;
	f[0][0]=1;
	for(int i=1;i<N;i++)f[i][s[i]]=1;
	for(int i=4;i<N;i++)f[i][i+1]=1;
	for(int i=1;i<N;i++)for(int j=i;j<=s[i];j++)if(f[i][j])
	{
		for(int k=2;k<=N-i;k++)f[i+k-1][j+s[k]-1]=1;
		for(int k=4;k<=N-i;k++)f[i+k-1][j+k]=1;
	}
}
void dfs(int l,int r,int n,int k,int op)
{
	if(k==n*(n+1)/2)
	{
		if(op==0)for(int i=l;i<=r;i++)ans[i]=++cc;
		else for(int i=r;i>=l;i--)ans[i]=++cc;return;
	}
	if(k==n+1)
	{
		for(int i=l+1;i<=r;i+=2)ans[i]=++cc;
		for(int i=l;i<=r;i+=2)ans[i]=++cc;
		if(n&1)swap(ans[r],ans[r-2]);return;
	}
	for(int i=2;i<=n;i++)if(k-s[i]+1>0&&f[n-i+1][k-s[i]+1])
	{
		if(!op)
		{
			dfs(l,r-i+1,n-i+1,k-s[i]+1,1);
			for(int j=r-i+2;j<=r;j++)ans[j]=++cc;
		}
		else
		{
			dfs(l+i-1,r,n-i+1,k-s[i]+1,0);
			for(int j=l+i-2;j>=l;j--)ans[j]=++cc;
		}
		return;
	}
	for(int i=4;i<=n;i++)if(k-i>0&&f[n-i+1][k-i])
	{
		for(int j=r-i+2;j<=r;j+=2)ans[j]=++cc;
		dfs(l,r-i+1,n-i+1,k-i,0);
		for(int j=r-i+3;j<=r;j+=2)ans[j]=++cc;
		if(i&1)swap(ans[r-2],ans[r]);
		return;
	}
}
void sol()
{
	int n,k;cc=0;scanf("%d%d",&n,&k);
	if(!f[n][k]){puts("NO");return;}
	dfs(1,n,n,k,0);puts("YES");
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);puts("");
}
int main(){init();int T;scanf("%d",&T);while(T--)sol();return 0;}

#include <bits/stdc++.h>
#define EB emplace_back
using std::cin;
using std::cout;

typedef long long ll;
typedef std::pair <int, int> pr;
typedef std::vector <int> vector;
const int N = 108, N2 = 5400;

enum type {invalid, conjunct, disjunct};

struct path {
	type S; pr last;
	path () {}
	path (type S_, pr la_) : S(S_), last(la_) {}
} f[N][N2];

int C2[N], last[N2];

inline void down(int &x, const int y) {x > y ? x = y : 0;}

void init() {
	int i, j, k;
	for (i = 1; i < 107; ++i) C2[i + 1] = C2[i] + i;
	f[1][0] = path(conjunct, {0, 0}),
	f[2][1] = path(conjunct, {1, 0}),
	f[3][2] = path(conjunct, {2, 1}),
	f[3][3] = path(conjunct, {1, 0}),
	last[1] = 2, last[2] = last[3] = 3;
	for (i = 4; i <= 100; ++i) {
		f[i][1] = path(disjunct, {1, 0}), f[i][C2[i]] = path(conjunct, {1, 0});
		// disjunct
		for (j = 2; j < C2[i]; ++j)
			if (last[j - 1] && last[j - 1] < i - 2)
				f[i][j] = path(disjunct, {last[j - 1], j - 1});
		// conjunct
		for (j = 2; j < C2[i]; ++j) if (f[i][j].S == invalid)
			for (k = 1; k < i && C2[k + 1] < j; ++k)
				if (f[i - k][j - C2[k + 1]].S != invalid) {
					f[i][j] = path(conjunct, {i - k, j - C2[k + 1]});
					break;
				}
		for (j = 1; j <= C2[i]; ++j) if (f[i][j].S != invalid && !last[j]) last[j] = i;
	}
}

vector recursion(int n, int W) {
	if (n == 1) return vector(1, 1);
	int i, m = f[n][W].last.first, deg = n - m + 1;
	vector ret(recursion(f[n][W].last.first, f[n][W].last.second));
	ret.reserve(n);
	if (f[n][W].S == conjunct) {
		assert(deg > 1);
		for (int &x : ret) x = m - x + 1;
		for (; ++m <= n; ret.EB(m));
	} else {
		assert(deg > 3);
		for (int &x : ret) ++x;
		for (i = 4; i <= deg; i += 2) ret.EB(i + m - 1);
		ret.EB(1);
		for (i = 3; i < deg - 2; i += 2) ret.EB(i + m - 1);
		if (deg & 1) ret.EB(n);
		ret.EB(i + m - 1);
	}
	return ret;
}

inline vector solve(int n, int W) {return n == 1 ? (W == 1 ? vector(1, 1) : vector()) : (W <= n || f[n][W - n].S == invalid ? vector() : recursion(n, W - n));}

int main() {
	int T, i, n, W; vector ret; init();
	std::ios::sync_with_stdio(false), cin.tie(NULL);
	for (cin >> T; T; --T) {
		cin >> n >> W, ret = solve(n, W);
		if (ret.empty()) cout << "NO\n";
		else for (cout << "YES\n", i = 0; i < n; ++i) cout << ret[i] << (i == n - 1 ? '\n' : ' ');
	}
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
using namespace std;
vi ca[105][105]; // i个数分成j段，总贡献为k，第一段大小 + 贡献 * 1024  *j = 1 最后更新*
int dp[105][6000]; // i个数总贡献为k，总段数 + 1024 * 合点
int cal(int x) {
	return x * (x - 1) / 2;
}
int r[105];
void work(int L, int R, int k, int bg, int tp) {
	if (L == R) {
		r[L] = bg;
		return;
	}

	int n = R - L + 1;
	int l = dp[n][k] % 1024;
	vi ns(l), res(l);
	int rtp = dp[n][k] & 1024;
	if (rtp) k -= cal(l);
	int fk = k;
	for (int j = 0; j < l; j++)
		ns[j] = ca[n][l - j][k] % 1024,
		res[j] = ca[n][l - j][k] / 1024,
		n -= ns[j],
		k -= res[j];
		/*
	cout << "W" << L << ' ' << R << ' ' << fk << ' ' << bg << ' ' << tp << ' ' << l << endl;
	for (int j = 0; j < l; j++)
		cout << ns[j] << ' ';
	cout << endl;
	system("pause");
	*/
	if (rtp) {
		if (tp)
			for (int j = 0; j < l; j++)
				work(L, L + ns[j] - 1, res[j], bg, tp ^ 1),
				L += ns[j], bg += ns[j];
		else
			for (int j = l - 1; j >= 0; j--)
				work(R - ns[j] + 1, R, res[j], bg, tp ^ 1),
				R -= ns[j], bg += ns[j];
	}
	else {
		vi p(l), q(l);
		int k = l / 2;
		if (l % 2 == 0) {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
		}
		else {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
			p[2 * k] = 2 * k;
			swap(p[l - 1], p[l - 2]);
		}
		for (int i = 0; i < l; i++) {
			int nl = L;
			for (int j = 0; j < l; j++) {
				if (p[j] == i) {
					work(nl, nl + ns[j] - 1, res[j], bg, tp);
					bg += ns[j];
					break;
				}
				nl += ns[j];
			}
		}
	}
}
int main() {
	for (int i = 1; i < 101; i++) {
		for (int j = 1; j <= i; j++) {
			ca[i][j].resize(j + cal(i + 2 - j));
			if (i == 1 && j == 1) ca[1][1][1] = 1025, dp[1][1] = 1;
			else
				if (j >= 2)
					for (int l = i; l < ca[i][j].size(); l++)
						for (int k = 1; k <= i / j; k++) {
							if (ca[i][j][l]) break;
							int mx1 = cal(k + 1), mx2 = ca[i - k][j - 1].size() - 1;
							int du = max(k, l - mx2);
							for (int s = du; s <= mx1; s++)
								if (dp[k][s] && ca[i - k][j - 1][l - s]) {
									ca[i][j][l] = k + s * 1024;
									break;
								}
						}
		}
		for (int l = i; l <= cal(i + 1); l++) {
			for (int m = 2; m <= i; m++) {
				int ed = l - cal(m);
				if (ca[i][m].size() > ed && ca[i][m][ed]) {
					dp[i][l] = 1024 + m;
					break;
				}
			}
			for (int m = 4; m <= i; m++)
				if (ca[i][m].size() > l && ca[i][m][l]) {
					dp[i][l] = m;
					break;
				}
			if (dp[i][l]) ca[i][1][l] = i + l * 1024;
		}
	}
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n, k;
		cin >> n >> k;
		if (!dp[n][k]) cout << "NO" << endl;
		else {
			cout << "YES" << endl;
			work(1, n, k, 1, 0);
			for (int j = 1; j <= n; j++)
				printf("%d ", r[j]);
			printf("\n");
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 105;

vector <int> adj[N * 2];
int f[N][N * N], g[N][N * N], ans[N];
int q, n, k;

int main() {
    f[1][1] = 233;
    for (int i = 1; i <= 100; i++) {
        for (int j = 0; j <= 5050; j++) {
            if (!f[i][j]) continue;
            for (int k = 2; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k * (k + 1) / 2]) {
                    f[i + k - 1][j + k * (k + 1) / 2 - 1] = k;
                    g[i + k - 1][j + k * (k + 1) / 2 - 1] = 1;
                }
            }
            for (int k = 4; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k]) {
                    f[i + k - 1][j + k] = k;
                    g[i + k - 1][j + k] = 2;
                }
            }
        }
    }
    read(q);
    while (q--) {
        read(n); read(k); int tmp = n;
        if (n == 1 && k == 1) {
            printf("YES\n1\n");
            continue;
        }
        // printf("! %d %d\n", f[n][k], g[n][k]);
        if (!f[n][k]) {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
        vector <pii> seq;
        while (n != 1 || k != 1) {
            seq.push_back(make_pair(f[n][k], g[n][k]));
            if (g[n][k] == 1) {
                int tmp = f[n][k];
                k -= (tmp * (tmp + 1) / 2 - 1);
                n -= (tmp - 1);
            } else {
                int tmp = f[n][k];
                k -= tmp;
                n -= (tmp - 1);
            }
        }
        int l = 1, r = tmp, pos = 0, opt = 0;
        for (int i = 0; i < (int)seq.size(); i++) {
            if (seq[i].second == 1) {
                if (opt == 0) {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 1); opt ^= 1;
                } else {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = r - j + 1;
                    r -= (seq[i].first - 1); opt ^= 1;
                }
            } else {
                if (seq[i].first % 2 == 0) {
                    for (int j = 2; j <= seq[i].first - 2; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r;
                    for (int j = 1; j <= seq[i].first - 3; j += 2) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 2); --r;
                } else {
                    for (int j = 2; j <= seq[i].first - 3; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r - 1;
                    for (int j = 1; j <= seq[i].first - 4; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r;
                    l += (seq[i].first - 3); r -= 2;
                }
            }
        }
        ans[++pos] = l;
        for (int i = 1; i <= tmp; i++) print(ans[i], i == tmp ? '\n' : ' ');
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 105;

vector <int> adj[N * 2];
int f[N][N * N], g[N][N * N], ans[N];
int q, n, k;

int main() {
    f[1][1] = 233;
    for (int i = 1; i <= 100; i++) {
        for (int j = 0; j <= 5050; j++) {
            if (!f[i][j]) continue;
            for (int k = 2; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k * (k + 1) / 2]) {
                    f[i + k - 1][j + k * (k + 1) / 2 - 1] = k;
                    g[i + k - 1][j + k * (k + 1) / 2 - 1] = 1;
                }
            }
            for (int k = 4; k <= 101 - i; k++) {
                if (!f[i + k - 1][j + k]) {
                    f[i + k - 1][j + k] = k;
                    g[i + k - 1][j + k] = 2;
                }
            }
        }
    }
    read(q);
    while (q--) {
        read(n); read(k); int tmp = n;
        if (n == 1 && k == 1) {
            printf("YES\n1\n");
            continue;
        }
        // printf("! %d %d\n", f[n][k], g[n][k]);
        if (!f[n][k]) {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
        vector <pii> seq;
        while (n != 1 || k != 1) {
            seq.push_back(make_pair(f[n][k], g[n][k]));
            if (g[n][k] == 1) {
                int tmp = f[n][k];
                k -= (tmp * (tmp + 1) / 2 - 1);
                n -= (tmp - 1);
            } else {
                int tmp = f[n][k];
                k -= tmp;
                n -= (tmp - 1);
            }
        }
        int l = 1, r = tmp, pos = 0, opt = 0;
        for (int i = 0; i < (int)seq.size(); i++) {
            if (seq[i].second == 1) {
                if (opt == 0) {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 1); opt ^= 1;
                } else {
                    for (int j = 1; j < seq[i].first; j++) ans[++pos] = r - j + 1;
                    r -= (seq[i].first - 1); opt ^= 1;
                }
            } else {
                if (seq[i].first % 2 == 0) {
                    for (int j = 2; j < seq[i].first; j += 2) ans[++pos] = l + j - 1;
                    ans[++pos] = r;
                    for (int j = 1; j < seq[i].first - 2; j += 2) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 2); --r;
                } else {
                    for (int j = 2; j <= seq[i].first; j += 2) ans[++pos] = l + j - 1;
                    for (int j = 1; j <= seq[i].first - 2; j += 2) ans[++pos] = l + j - 1;
                    l += (seq[i].first - 1);
                }
            }
        }
        ans[++pos] = l;
        for (int i = 1; i <= tmp; i++) print(ans[i], i == tmp ? '\n' : ' ');
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MAX_N=105;
vector<int> ans[MAX_N][MAX_N*MAX_N];
vector<pair<int,int>> que;
void bfs(int p){
    if(p==que.size()){
        return;
    }
    auto [a1,b1]=que[p];
    for(int i=1;i<=p;++i){
        auto [a2,b2]=que[i];
        int a3=a1+a2-1;
        int b3=b1+b2-1;
        if(a3<=100&&ans[a3][b3].empty()){
            for(int x:ans[a2][b2]){
                ans[a3][b3].push_back(ans[a1][b1].front()+x-1);
            }
            for(int x:ans[a1][b1]){
                if(x!=ans[a1][b1].front()){
                    ans[a3][b3].push_back(x<ans[a1][b1].front()?x:x+a2);
                }
            }
            int x=min(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            int y=max(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            if(ans[a3][b3].front()<x||ans[a3][b3].front()>y){
                reverse(ans[a3][b3].begin(),ans[a3][b3].begin()+a2);
            }
            que.emplace_back(a3,b3);
        }
    }
    bfs(p+1);
}
int main(){
    for(int i=1;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i*(i+1)/2].push_back(j);
        }
    }
    for(int i=4;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i+1].push_back((j&1)?(j+i+1)/2:j/2);
        }
        if(i&1){
            swap(ans[i][i+1][i-3],ans[i][i+1][i-1]);
        }
    }
    for(int a=2;a<=100;++a){
        for(int b=a+1;b<=a*(a+1)/2;++b){
            if(ans[a][b].empty()){
                bool ok=false;
                for(int a1=4;a1<=a&&!ok;++a1){
                    int b1=a1+1;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2-1);
                        }
                        ok=true;
                    }
                }
                for(int a1=2;a1<=a&&a1*(a1+1)/2<=b&&!ok;++a1){
                    int b1=a1*(a1+1)/2;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2-1);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2);
                        }
                        ok=true;
                    }
                }
            }
        }
    }
    int T;
    cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        if(ans[a][b].empty()){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            for(int x:ans[a][b]){
                cout<<x<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MAX_N=105;
vector<int> ans[MAX_N][MAX_N*MAX_N];
vector<pair<int,int>> que;
void bfs(int p){
    if(p==que.size()){
        return;
    }
    auto [a1,b1]=que[p];
    for(int i=1;i<=p;++i){
        auto [a2,b2]=que[i];
        int a3=a1+a2-1;
        int b3=b1+b2-1;
        if(a3<=100&&ans[a3][b3].empty()){
            for(int x:ans[a2][b2]){
                ans[a3][b3].push_back(ans[a1][b1].front()+x-1);
            }
            for(int x:ans[a1][b1]){
                if(x!=ans[a1][b1].front()){
                    ans[a3][b3].push_back(x<ans[a1][b1].front()?x:x+a2);
                }
            }
            int x=min(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            int y=max(ans[a3][b3][a2-1],ans[a3][b3][a2]);
            if(ans[a3][b3].front()<x||ans[a3][b3].front()>y){
                reverse(ans[a3][b3].begin(),ans[a3][b3].begin()+a2);
            }
            que.emplace_back(a3,b3);
        }
    }
    bfs(p+1);
}
int main(){
    for(int i=1;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i*(i+1)/2].push_back(j);
        }
    }
    for(int i=4;i<=100;++i){
        for(int j=1;j<=i;++j){
            ans[i][i+1].push_back((j&1)?(j+i+1)/2:j/2);
        }
        if(i&1){
            swap(ans[i][i+1][i-3],ans[i][i+1][i-1]);
        }
    }
    for(int a=2;a<=100;++a){
        for(int b=a+1;b<=a*(a+1)/2;++b){
            if(ans[a][b].empty()){
                bool ok=false;
                for(int a1=4;a1<=a&&!ok;++a1){
                    int b1=a1+1;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2);
                        }
                        ok=true;
                    }
                }
                for(int a1=2;a1<=a&&a1*(a1+1)/2<=b&&!ok;++a1){
                    int b1=a1*(a1+1)/2;
                    int a2=a-a1+1;
                    int b2=b-b1+1;
                    if(!ans[a2][b2].empty()){
                        for(int x:ans[a2][b2]){
                            ans[a][b].push_back(ans[a1][b1].front()+x-1);
                        }
                        for(int x:ans[a1][b1]){
                            if(x!=ans[a1][b1].front()){
                                ans[a][b].push_back(x<ans[a1][b1].front()?x:x+a2-1);
                            }
                        }
                        int x=min(ans[a][b][a2-1],ans[a][b][a2]);
                        int y=max(ans[a][b][a2-1],ans[a][b][a2]);
                        if(ans[a][b].front()<x||ans[a][b].front()>y){
                            reverse(ans[a][b].begin(),ans[a][b].begin()+a2);
                        }
                        ok=true;
                    }
                }
            }
        }
    }
    int T;
    cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        if(ans[a][b].empty()){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
            for(int x:ans[a][b]){
                cout<<x<<' ';
            }
            cout<<endl;
        }
    }
    return 0;
}

// ███▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓╬╬╬╬╬╬▓█
// ███▓███████▓▓╬╬╬╬╬╬╬╬╬╬╬╬▓███▓▓▓▓█▓╬╬╬▓█
// ███████▓█████▓▓╬╬╬╬╬╬╬╬▓███▓╬╬╬╬╬╬╬▓╬╬▓█
// ████▓▓▓▓╬╬▓█████╬╬╬╬╬╬███▓╬╬╬╬╬╬╬╬╬╬╬╬╬█
// ███▓▓▓▓╬╬╬╬╬╬▓██╬╬╬╬╬╬▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬╬╬╬▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓███████▓▓███▓╬╬╬╬╬╬▓███████▓╬╬╬╬▓█
// ████████████████▓█▓╬╬╬╬╬▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬█
// ███▓▓▓▓▓▓▓╬╬▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ████▓▓▓╬╬╬╬▓▓▓▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// ███▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓▓█▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█
// █████▓▓▓▓▓▓▓██▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// █████▓▓▓▓▓████▓▓▓█▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓█▓▓▓▓██▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ████▓▓███▓▓▓▓▓▓▓██▓╬╬╬╬╬╬╬╬╬╬╬╬█▓╬▓╬╬▓██
// █████▓███▓▓▓▓▓▓▓▓████▓▓╬╬╬╬╬╬╬█▓╬╬╬╬╬▓██
// █████▓▓█▓███▓▓▓████╬▓█▓▓╬╬╬▓▓█▓╬╬╬╬╬╬███
// ██████▓██▓███████▓╬╬╬▓▓╬▓▓██▓╬╬╬╬╬╬╬▓███
// ███████▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬████
// ███████▓▓██▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓████
// ████████▓▓▓█████▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓█████
// █████████▓▓▓█▓▓▓▓▓███▓╬╬╬╬╬╬╬╬╬╬╬▓██████
// ██████████▓▓▓█▓▓▓╬▓██╬╬╬╬╬╬╬╬╬╬╬▓███████
// ███████████▓▓█▓▓▓▓███▓╬╬╬╬╬╬╬╬╬▓████████
// ██████████████▓▓▓███▓▓╬╬╬╬╬╬╬╬██████████
// ███████████████▓▓▓██▓▓╬╬╬╬╬╬▓███████████
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define mp make_pair
#define len(a) int(a.size())
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout)
using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }

typedef long long base;
typedef pair<int, int> point;
typedef complex<double> comp;

const int N = 101;
const int T = 5;

int n;
bool used[N * N];
pair<point, point> how[N * N];

vector<int> can[N];
vector<pair<point, point>> way[N];
vector<int> answer[T][T * T];

void init_small() {
	for (int i = 1; i < T; ++i) {
		vector<int> res;
		for (int j = 1; j <= i; ++j) res.pb(j);
		do {
			int cnt = 0;
			for (int L = 0; L < i; ++L) {
				for (int R = L + 1; R <= i; ++R) {
					int minx = 1e9, maxx = -1e9;
					for (int M = L; M < R; ++M) {
						chkmax(maxx, res[M]);
						chkmin(minx, res[M]);
					}
					if (maxx - minx + 1 == R - L) {
						++cnt;
					}
				}
			}
			answer[i][cnt] = res;
		} while (next_permutation(res.begin(), res.end()));
		for (int j = 0; j <= (i + 1) * i / 2; ++j) {
			if (answer[i][j].size()) {
				can[i].pb(j);
			}
		}
	}
}

void init_big() {
	for (int a = T; a < N; ++a) {
		memset(used, 0, sizeof(used));
		for (int b = 2; b * 2 < a; ++b) {
			int c = a + 1 - b;
			for (int wb : can[b]) {
				for (int wc : can[c]) {
					used[wb + wc - 1] = true;
					how[wb + wc - 1] = {{b, wb}, {c, wc}};
				}
			}
		}
		can[a].pb(a + 1);
		way[a].pb({{-1, -1}, {-1, -1}});
		for (int i = a + 2; i < a * (a + 1) / 2; ++i) {
			if (used[i]) {
				can[a].pb(i);
				way[a].pb(how[i]);
			}
		}
		can[a].pb(a * (a + 1) / 2);
		way[a].pb({{-1, -1}, {-1, -1}});
	}
}

void get(int a, int b, vector<int> &ans) {
	if (a < T) {
		ans = answer[a][b];
		return;
	}
	int it = lower_bound(can[a].begin(), can[a].end(), b) - can[a].begin();
	if (can[a][it] != b) return;
	if (b == a * (a + 1) / 2) {
		ans.resize(a);
		for (int i = 0; i < a; ++i) {
			ans[i] = i + 1;
		}
		return;
	}
	if (b == a + 1) {
		for (int i = 2; i <= a; i += 2) {
			ans.pb(i);
		}
		ans.pb(1);
		if (a & 1) ans.pb(a);
		for (int i = 3; i < a; i += 2) {
			ans.pb(i);
		}
		return;
	}
	vector<int> L, R;
	get(way[a][it].x.x, way[a][it].x.y, L);
	get(way[a][it].y.x, way[a][it].y.y, R);
	ans.resize(a);
	for (int i = 0; i < L.size(); ++i) ans[i] = L[i] + R[0] - 1;
	for (int i = 1; i < R.size(); ++i) {
		ans[L.size() + i - 1] = R[i] + int(R[i] > R[0]) * (L.size() - 1);
	}
	if ((ans[0] < ans[L.size() - 1]) == (ans[L.size() - 1] < ans[L.size()])) {
		reverse(ans.begin(), ans.begin() + L.size());
	}
}

int main() {
    ios::sync_with_stdio(0);
    srand(time(0));
    init_small();
    init_big();
    int t;
    cin >> t;
    while (t--) {
    	vector<int> ans;
    	int a, b;
    	cin >> a >> b;
    	get(a, b, ans);
    	if (ans.size() == 0) {
    		cout << "NO\n";
    	} else {
    		cout << "YES\n";
    		cout << ans << '\n';
    	}
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
int const N=100;
bool dp[N+1][N*N];
vector<int>g[N+1];
pair<int,int>bck[N+1][N*N];
void no()
{
	printf("NO\n");
}
vector<int> go(int n,int m)
{
	if(m==n+1)
	{
		vector<int>an(n);
		int t=1,i=0;
		while(t<n)an[i++]=t,t+=2;
		reverse(an.begin(),an.begin()+i);
		an[i++]=n;
		t=2;
		while(t<n)an[i++]=t,t+=2;
		return an;
	}
	if(m==n*(n+1)>>1)
	{
		vector<int>an(n);
		f(i,0,n)an[i]=i+1;
		return an;
	}
	int n1=bck[n][m].first,m1=bck[n][m].second;
	vector<int>a=go(n1,m1),b=go(n-n1+1,m-m1+1);
	f(i,0,a.size())a[i]+=b[0]-1;
	int t=a.size();
	a.insert(a.end(),b.begin()+1,b.end());
	f(i,t,a.size())if(a[i]>b[0])a[i]+=t-1;
	if(a[t]>a[t-1]&&a[t-1]>a[0]||a[t]<a[t-1]&&a[t-1]<a[0])reverse(a.begin(),a.begin()+t);
	return a;
}
void solve()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n==1)
	{
		printf("YES\n1\n");
		return;
	}
	if(!dp[n][m])return no();
	vector<int>an=go(n,m);
	printf("YES\n%d",an[0]);
	f(i,1,n)printf("%d",an[i]);
	printf("\n");
}
int main(void)
{
	f(i,2,N+1)
	{
		if(i!=3)dp[i][i+1]=true;
		int lm=i*(i+1)>>1;
		dp[i][lm]=true;
		f(j,i+1,lm+1)if(dp[i][j])g[i].push_back(j);
		f(j,2,i+1)if(i+j-1<=N)f(k,0,g[i].size())f(w,0,g[j].size())if(!dp[i+j-1][g[i][k]+g[j][w]-1])
		{
			dp[i+j-1][g[i][k]+g[j][w]-1]=true;
			bck[i+j-1][g[i][k]+g[j][w]-1]=make_pair(i,g[i][k]);
		}
	}
	int t;
	scanf("%d",&t);
	while(t--)solve();
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
bool exist[101][51 * 101];
int main()
{
	for (int i = 1; i <= 100; i++)
		for (int j = 1; j <= i * (i + 1) / 2; j++)
			exist[i][j] = false;
	exist[1][1] = exist[2][3] = true;
	exist[3][5] = exist[3][6] = true;
	for (int i = 4; i <= 100; i++) {
		exist[i][i + 1] = exist[i][i*(i + 1) / 2] = true;
		for (int j = i + 2; j < i * (i + 1) / 2; j++) {
			for (int k = 2; k <= i - 1; k++)
				if (j + 1 - k * (k + 1) / 2 > i + 1 - k && exist[i + 1 - k][j + 1 - k * (k + 1) / 2]) {
					exist[i][j] = true;
					break;
				}
			if (!exist[i][j])
				for (int k = 4; k <= i - 1; k++)
					if (j > i + 1 && exist[i + 1 - k][j - k]) {
						exist[i][j] = true;
						break;
					}
		}
	}
	int q, n, k;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		cin >> n >> k;
		if (exist[n][k]) cout << "YES" << endl; else cout << "NO" << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const int MAXM = 5055;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
bool dp[MAXN][MAXM];
int main() {
	int n = 100, m = 5050; dp[1][1] = true;
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++) {
		if (!dp[i][j]) continue;
		for (int k = 4; i + k - 1 <= n; k++)
			dp[i + k - 1][j + k] = true;
		for (int k = 2; i + k - 1 <= n; k++)
			dp[i + k - 1][j + k * (k + 1) / 2 - 1] = true;
	}
	int T; read(T);
	while (T--) {
		read(n), read(m);
		if (dp[n][m]) {
			puts("YES"); int cur = 2;
			deque <int> ans; ans.push_back(1);
			while (n != 1) {
				for (int k = 2; k <= n; k++)
					if (m - k * (k + 1) / 2 + 1 >= 1 && dp[n - k + 1][m - k * (k + 1) / 2 + 1]) {
						for (int i = 2; i <= k; i++, n--)
							ans.push_back(cur++);
						m -= k * (k + 1) / 2 - 1;
						break;
					}
				for (int k = 4; k <= n; k++)
					if (m - k >= 1 && dp[n - k + 1][m - k]) {
						int bak = cur++;
						for (int i = 3; i <= k; i++, n--)
							if (i & 1) ans.push_back(cur++);
							else ans.push_front(cur++);
						if (k & 1) ans.push_back(bak);
						else ans.push_front(bak);
						n--, m -= k;
						break;
					}
			}
			while (!ans.empty()) {
				printf("%d ", ans.front());
				ans.pop_front();
			}
			printf("\n");
		} else puts("NO");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 100;
vector <int> dp[N + 3][N * (N - 1) / 2 + 3], biao[N + 3];

int main(void) {
	biao[4] = {1, 4, 2, 3};
	for (int i = 5; i <= N; i++) {
		rep (j, i) if (j & 1) biao[i].push_back(j);
		rep (j, i) if (~j & 1) biao[i].push_back(j);
	}
	dp[1][1] = {1}; dp[2][3] = {1, 2};
	for (int i = 1; i <= N; i++) {
		for (int has = 0; has <= i * (i + 1) / 2; has++)
			if (dp[i][has].size()) {
				for (int k = 2; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k * (k + 1) / 2 - 1];
					if (t.size()) continue;
					t = dp[i][has];
					if (t.back() == t.size()) reverse(t.begin(), t.end());
					while (t.size() < i + k - 1) t.push_back(t.size() + 1);
				}
				for (int k = 4; k + i - 1 <= N; k++) {
					auto &t = dp[i + k - 1][has + k];
					if (t.size()) continue;
					for (auto p : biao[k])
						if (p == 1)
							for (auto s : dp[i][has]) t.push_back(s);
						else t.push_back(i + p - 1);
				}
				// cout << i << " " << has << " : ";
				// for (auto t : dp[i][has]) cout << t << " " ; cout <<"\n";
			}
	}
	int q;
	read(q);
	rep (i, q) {
		int n, k;
		read(n); read(k);
		auto &t = dp[n][k];
		if (!t.size()) cout << "NO\n";
		else {
			cout << "YES\n";
			for (auto s : t) cout << s << " ";
			cout << "\n";
		}
	}

}

#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=105;
int a[N];
int dp[N][N*N];
void prework(){
	int n=N-5;
	dp[1][0]=1;
	For(i,1,n)
		For(j,0,i*(i-1)/2)
			if (dp[i][j]){
				For(k,1,n-i){
					dp[i+k][j+(k+1)*k/2]=i;
					if (~k&1&&k>2)
						dp[i+k][j+1]=-i;
				}
			}
}
void Solve(){
	int n=read(),k=read();
	k-=n;
	if (k<0||!dp[n][k])
		return (void)puts("NO");
	For(i,1,n)
		a[i]=i;
	for (int i=n,j;i>1;i=j){
		j=dp[i][k];
		if (j>0){
			reverse(a+i,a+n+1);
			k-=(i-j)*(i-j+1)/2;
		}
		else {
			k--;
			j=abs(j);
			int len=n-i+1;
			int m=i-j+1;
			int Lp=j+m/2,Rp=Lp+len-1;
			For(p,Lp,Rp)
				a[p]=a[p-Lp+i];
			For(v,1,m-1)
				if (v&1)
					a[--Lp]=v+j-1;
				else
					a[++Rp]=v+j-1;
		}
//		outarr(a,1,n);
//		outval(j),outval(k);
	}
	puts("YES");
	For(i,1,n)
		printf("%d ",a[i]);
	puts("");
}
int main(){
	prework();
	int T=read();
	while (T--)
		Solve();
	return 0;
}

#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=105;
int a[N];
int dp[N][N*N];
void prework(){
	int n=N-5;
	dp[1][0]=1;
	For(i,1,n)
		For(j,0,i*(i-1)/2)
			if (dp[i][j]){
				For(k,1,n-i){
					dp[i+k][j+(k+1)*k/2]=i;
					if (~k&1&&k>2)
						dp[i+k][j+1]=-i;
				}
			}
}
void Solve(){
	int n=read(),k=read();
	k-=n;
	if (!dp[n][k])
		return (void)puts("NO");
	For(i,1,n)
		a[i]=i;
	for (int i=n,j;i>1;i=j){
		j=dp[i][k];
		if (j>0){
			reverse(a+i,a+n+1);
			k-=(i-j)*(i-j+1)/2;
		}
		else {
			k--;
			j=abs(j);
			int len=n-i+1;
			int m=i-j+1;
			int Lp=j+m/2,Rp=Lp+len-1;
			For(p,Lp,Rp)
				a[p]=a[p-Lp+i];
			For(v,1,m-1)
				if (v&1)
					a[--Lp]=v+j-1;
				else
					a[++Rp]=v+j-1;
		}
//		outarr(a,1,n);
//		outval(j),outval(k);
	}
	puts("YES");
	For(i,1,n)
		printf("%d ",a[i]);
	puts("");
}
int main(){
	prework();
	int T=read();
	while (T--)
		Solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 100;
bool dp[N + 1][N * N];
vector<int> g[N + 1];
pair<int, int> bck[N + 1][N * N];

void no() { printf("NO\n"); }

vector<int> go(int n, int m){
	if (m == n + 1){
		vector<int> an(n);
		int t = 1, i = 0;
		while (t < n)an[i++] = t, t += 2;
		reverse(an.begin(), an.begin() + i);
		an[i++] = n;
		t = 2;
		while (t < n)an[i++] = t, t += 2;
		return an;
	}
	if (m == n * (n + 1) >> 1){
		vector<int> an(n);
		f(i, 0, n)an[i] = i + 1;
		return an;
	}
	int n1 = bck[n][m].first, m1 = bck[n][m].second;
	vector<int> a = go(n1, m1), b = go(n - n1 + 1, m - m1 + 1);
	f(i, 0, a.size())a[i] += b[0] - 1;
	int t = a.size();
	a.insert(a.end(), b.begin() + 1, b.end());
	f(i, t, a.size())if (a[i] > b[0])a[i] += b.size() - 1;
	if (a[t] > a[t - 1] && a[t - 1] > a[0] || a[t] < a[t - 1] && a[t - 1] < a[0])reverse(a.begin(), a.begin() + t);
	return a;
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	if (n == 1) {
		printf("YES\n1\n");
		return;
	}
	if (!dp[n][m])return no();
	vector<int> an = go(n, m);
	printf("YES\n%d", an[0]);
	f(i, 1, n)printf(" %d", an[i]);
	printf("\n");
}

int main(){
	//int tz = clock();
	f(i, 2, N + 1){
		if (i != 3)dp[i][i + 1] = true;
		int lm = i * (i + 1) >> 1;
		dp[i][lm] = true;
		f(j, i + 1, lm + 1)if (dp[i][j])g[i].push_back(j);
		f(j, 2, i + 1)if (i + j - 1 <= N)f(k, 0, g[i].size())f(w, 0, g[j].size())if (!dp[i + j - 1][g[i][k] + g[j][w] - 1]){
			dp[i + j - 1][g[i][k] + g[j][w] - 1] = true;
			bck[i + j - 1][g[i][k] + g[j][w] - 1] = make_pair(i, g[i][k]);
		}
	}
	/*int an = 0;
	f(i, 2, N + 1)an += g[i].size();
	printf("%d\n", an);
	printf("%lf\n", (clock() - tz) / (double)CLOCKS_PER_SEC);
	return 0;*/
	int t;
	scanf("%d", &t);
	while (t--)solve();
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <complex>

#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3c3c3c3c;
const ll LINF = 1ll*INF*INF*2;

const int N = 101;
int n,m;

pii dp[101][5100];
pii Z={0,0};

void find(int x, int y, vector<int> &v) {
	if(x==1 && y==1) {v.push_back(1); return;}
	if(y==x*(x+1)/2) {
		for(int i=1; i<=x; i++) v.push_back(i);
		return;
	}
	if(y==x+1) {
		for(int i=2; i<=x; i+=2) v.push_back(i);
		v.push_back(1);
		int t=sz(v);
		for(int i=3; i<=x; i+=2) v.push_back(i);
		reverse(v.begin()+t, v.end());
		return;
	}
	vector<int> t2;
	int x1=dp[x][y].first;
	int y1=dp[x][y].second;
	int x2=x-x1+1;
	int y2=y-y1+1;
	find(x1, y1, v);
	find(x2, y2, t2);
	int P=t2[0];
	for(int i=0; i<sz(v); i++) v[i]+=P-1;
	for(int i=1; i<sz(t2); i++) {
		if(t2[i]<P) v.push_back(t2[i]);
		else v.push_back(t2[i]+x1-1);
	}
	if( (v[0]<v[x1-1] && v[0]<v[x1]) || (v[0]>v[x1-1] && v[0]>v[x1]) ) reverse(v.begin(), v.begin()+x1);
}
int main(void){
	dp[1][1]={1,1};
	for(int i=4; i<=100; i++) dp[i][i+1]={1,1};
	for(int i=2; i<=100; i++) dp[i][i*(i+1)/2]={1,1};
	for(int i=2; i<=100; i++) {
		for(int j=2; j<=i; j++) {
			if(i+j>100) break;
			for(int ii=i+1; ii<=i*(i+1)/2; ii++) {
				if(dp[i][ii]==Z) continue;
				for(int jj=j+1; jj<=j*(j+1)/2; jj++) {
					if(dp[j][jj]==Z) continue;
					dp[i+j-1][ii+jj-1]={i,ii};
				}
			}
		}
	}

	scanf("%d", &n);
	while(n--) {
		int x,y;
		scanf("%d%d", &x, &y);
		if(dp[x][y]==Z) {printf("NO\n"); continue;}

		printf("YES\n");
		vector<int> v;
		find(x,y,v);
		for(int e : v) printf("%d ", e); printf("\n");
	}
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <complex>

#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3c3c3c3c;
const ll LINF = 1ll*INF*INF*2;

const int N = 101;
int n,m;

pii dp[101][5100];
pii Z={0,0};

void find(int x, int y, vector<int> &v) {
	if(x==1 && y==1) {v.push_back(1); return;}
	if(y==x*(x+1)/2) {
		for(int i=1; i<=x; i++) v.push_back(i);
		return;
	}
	if(y==x+1) {
		for(int i=2; i<=x; i+=2) v.push_back(i);
		v.push_back(1);
		int t=sz(v);
		for(int i=3; i<=x; i+=2) v.push_back(i);
		reverse(v.begin()+t, v.end());
		return;
	}
	vector<int> t2;
	int x1=dp[x][y].first;
	int y1=dp[x][y].second;
	int x2=x-x1+1;
	int y2=y-y1+1;
	find(x1, y1, v);
	find(x2, y2, t2);
	int P=t2[0];
	for(int i=0; i<sz(v); i++) v[i]+=P-1;
	for(int i=1; i<sz(t2); i++) {
		if(t2[i]<P) v.push_back(t2[i]);
		else v.push_back(t2[i]+x1-1);
	}
}
int main(void){
	dp[1][1]={1,1};
	for(int i=4; i<=100; i++) dp[i][i+1]={1,1};
	for(int i=2; i<=100; i++) dp[i][i*(i+1)/2]={1,1};
	for(int i=2; i<=100; i++) {
		for(int j=2; j<=i; j++) {
			if(i+j>100) break;
			for(int ii=i+1; ii<=i*(i+1)/2; ii++) {
				if(dp[i][ii]==Z) continue;
				for(int jj=j+1; jj<=j*(j+1)/2; jj++) {
					if(dp[j][jj]==Z) continue;
					dp[i+j-1][ii+jj-1]={i,ii};
				}
			}
		}
	}

	scanf("%d", &n);
	while(n--) {
		int x,y;
		scanf("%d%d", &x, &y);
		if(dp[x][y]==Z) {printf("NO\n"); continue;}

		printf("YES\n");
		vector<int> v;
		find(x,y,v);
		for(int e : v) printf("%d ", e); printf("\n");
	}
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=110;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,k,tt,ans[N];
bool f[N][N*N];

void solve(int l,int r,int k,bool op) {
	//cerr<<"solve:"<<l<<' '<<r<<' '<<k<<' '<<op<<'\n';
	if(l==r) {
		ans[l]=++tt;return;
	}
	int n=r-l+1;
	for(int i=4;n-i+1>0;i++)
		if(f[n-i+1][k-i]) {
			for(int j=r-i+2;j<=r;j+=2) ans[j]=++tt;
			solve(l,r-i+1,k-i,0);
			for(int j=r-i+3;j<=r;j+=2) ans[j]=++tt;
			if(n&1) swap(ans[r],ans[r-2]);
			return;
		}
	for(int i=2;n-i+1>0;i++)
		if(f[n-i+1][k-i*(i+1)/2+1]) {
			if(!op) {
				solve(l,r-i+1,k-i*(i+1)/2+1,1);
				for(int j=r-i+2;j<=r;j++) ans[j]=++tt;
			}
			else {
				solve(l+i-1,r,k-i*(i+1)/2+1,0);
				for(int j=l+i-2;j>=l;j--) ans[j]=++tt;
			}
			return;
		}
	assert(!"gzyakioi2020");
}

int main() {
	f[1][1]=1;
	for(int i=1;i<N;i++)
		for(int j=0;j<=i*(i+1)/2;j++)
			if(f[i][j]) {
				for(int k=4;i+k-1<N;k++) f[i+k-1][j+k]=1;
				for(int k=2;i+k-1<N;k++) f[i+k-1][j+k*(k+1)/2-1]=1;
			}
	//cerr<<"f[2][1]="<<f[2][1]<<'\n';
	int T=gi();
	while(T--) {
		cin>>n>>k;tt=0;
		if(!f[n][k]) puts("NO");
		else {
			puts("YES");
			solve(1,n,k,0);
			for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
			cout<<'\n';
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=105;
int zy[N][N*N/2];
bool dp[N][N*N/2];
deque<int> ans;
int id;
void dfs(int n,int k){
	if(n==1){
		ans.push_back(1); return;
	}else{
		if(zy[n][k]>0){
			dfs(n-zy[n][k]+1,k-zy[n][k]);
			int sz=ans.size();
			if(zy[n][k]&1){
				ans.push_front(zy[n][k]/2+sz);
				for(int i=1;i<zy[n][k]/2-1;i++){ans.push_back(sz+i); ans.push_back(sz+zy[n][k]/2+i);}
				ans.push_back(sz+zy[n][k]-1);
				ans.push_back(sz+zy[n][k]/2-1);
				ans.push_back(sz+zy[n][k]-2);
			}else{
				ans.push_front(zy[n][k]/2+sz);
				for(int i=1;i<zy[n][k]/2;i++){ans.push_back(sz+i); ans.push_back(sz+zy[n][k]/2+i);}
			}
		}else{
			dfs(n+zy[n][k]+1,k+zy[n][k]*(1-zy[n][k])/2+1);
			int sz=ans.size();
			if(id){
				For(i,1,-zy[n][k]-1)ans.push_back(sz+i);
			}else{
				For(i,1,-zy[n][k]-1)ans.push_front(sz+i);
			}
			id^=1;
		}
	}
}
int main(){
	dp[1][1]=1;
	For(i,2,100){
		For(j,i,i*(i+1)/2){
			For(k,2,i){
				if(k*(k+1)/2<=j&&dp[i-k+1][j-k*(k+1)/2+1]){
					dp[i][j]=1; zy[i][j]=-k; break;
				}
				if(k>=4&&dp[i-k+1][j-k]){
					dp[i][j]=1; zy[i][j]=k; break;
				}
			}
		}
	}
	int q=read();
	while(q--){
		int n=read(),k=read();
		if(!dp[n][k]){puts("NO");}
		else{
			id=1;
			dfs(n,k);
			puts("YES");
			while(ans.size()){
				wri(ans.front()); ans.pop_front();
			}puts("");
		}
	}
}

//
// Created by Feng Xinyu on 8/23/19.
//
//thought:
// if dp[n][k] exists and equal to c, then, there must exists m, l that permutation m can be transformed to n by an
// monotonic order of n - m + 1(k(k+1)/2) or an disorder of n - m + 1(k+1).
// even if dp[n][k] can be formed by several dp[a][b],dp[a1][b1].....
#include <iostream>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair;
#define PI pair<int, int>
#define For(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define Rep(i, r, l) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second

const int N = 105;
int zy[N][N * N / 2];
bool dp[N][N * N / 2];
deque<int> ans;

void dfs(int n, int k) {
    if (n == 1) {
        ans.pb(1);
        return;
    } else {
        if (zy[n][k] > 0) {
            dfs(n - zy[n][k] + 1, k - zy[n][k]);
            int sz = ans.size();
            ans.pf(zy[n][k] / 2 + sz);
            if (zy[n][k] & 1) {
                For (i, 1, zy[n][k] / 2 - 2) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
                ans.pb(sz + zy[n][k] - 1);
                ans.pb(sz + zy[n][k] / 2 - 1);
                ans.pb(sz + zy[n][k] - 2);
            } else {
                For (i, 1, zy[n][k] / 2 - 1) {
                    ans.pb(sz + zy[n][k] / 2 + i);
                    ans.pb(sz + i);
                }
            }
        } else {
            dfs(n + zy[n][k] + 1, k + zy[n][k] * (1 - zy[n][k]) / 2 + 1);
            int sz = ans.size();
            if (ans.front() > ans.back()) {
                For (i, 1, -zy[n][k] - 1) ans.pb(sz + i);
            } else {
                For (i, 1, -zy[n][k] - 1) ans.pf(sz + i);
            }
        }
    }
}

int main() {
    dp[1][1] = 1;
    For(i, 2, 100) {
        For(j, i + 1, i * (i + 1) / 2 - 1) {
            For(k, 2, i) {
                if ( k == 2 && k * (k + 1) / 2 <= j && dp[i - (k - 1)][j - (k * (k + 1) / 2 - 1)]) {
                    dp[i][j] = 1; zy[i][j] = -k; break;
                }

                if (k >= 4 && dp[i - k + 1][j - k]) {
                    dp[i][j] = 1; zy[i][j] = k; break;
                }
            }
        }
        dp[i][i * (i + 1) / 2] = 1; zy[i][i * (i + 1) / 2] = -i;
    }

    int q, n, k;
    cin >> q;
    while (q--) {
        cin >> n >> k;
        if (!dp[n][k]) { puts("NO"); }
        else {
            dfs(n, k);
            puts("YES");
            while (ans.size()) {
                cout << ans.front() << ' ';
                ans.pop_front();
            }
            cout << endl;
        }
    }
    return 0;
}

#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4951];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=4950; ++j)
			if(f[i][j]) {
				for(int l=2; i+l<=100; ++l) f[i+l-1][j+l*(l-1)/2]=l;
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=4950; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(k<0) puts("NO"); else if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}

#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4951];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=4950; ++j)
			if(f[i][j]) {
				for(int l=2; i+l<=100; ++l) f[i+l-1][j+l*(l-1)/2]=l;
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=4950; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 110, N = 100;
pair<int, int> p[maxn][maxn * maxn];
int ta[maxn], tb[maxn], cnt, tp[maxn], ans[maxn];
void calc(int a, int b) {
	int a1 = p[a][b].first, b1 = p[a][b].second, a2 = a + 1- a1, b2 = b + 1 - b1;
	if(a1 == a) {
		ta[++cnt] = a; tb[cnt] = b; return;
	}
	calc(a1, b1); calc(a2, b2);
}
void getp(int a, int b) {
	if(b == a + 1) {
		int num = 0;
		for(int i = 2; i <= a; i += 2) tp[++num] = i;
		tp[++num] = 1; num = a;
		for(int i = 3; i <= a; i += 2) tp[num--] = i;
		return;
	}
	if(b == a * (a + 1) / 2) {
		rep(i, 1, a) tp[i] = i;
		return;
	}
	tp[1] = 1;
}
int main() {
	p[1][1] = make_pair(1, 1);
	rep(a, 2, N) {
		if(a != 3) p[a][a + 1] = make_pair(a, a + 1);
		p[a][a * (a + 1) / 2] = make_pair(a, a * (a + 1) / 2);
		rep(a1, 2, a - 1) {
			int a2 = a + 1 - a1;
			rep(b1, a1 + 1, a1 * (a1 + 1) / 2) if(p[a1][b1].first)
				rep(b2, a2 + 1, a2 * (a2 + 1) / 2) if(p[a2][b2].first) {
					p[a][b1 + b2 - 1] = make_pair(a1, b1);
					//cout << a << ' ' << b1 + b2 - 1 << endl;
				}
		}
	}
	int Q; scanf("%d", &Q);
	while(Q--) {
		int a, b; scanf("%d%d", &a, &b);
		if(!p[a][b].first) { printf("NO\n"); continue; }
		printf("YES\n");
		cnt = 0;
		calc(a, b);
		int num = 0;
		rep(i, 1, cnt) {
			getp(ta[i], tb[i]);
			if(!num) rep(j, 1, ta[j]) ans[++num] = tp[j];
			else {
				int tmp = ans[num]; num--;
				rep(j, 1, num) if(ans[j] > tmp) ans[j] += ta[i] - 1;
				rep(j, 1, ta[i]) ans[++num] = tp[j] + tmp - 1;
			}
		}
		rep(i, 1, a) printf("%d ", ans[i]);
		printf("\n");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 110, N = 100;
pair<int, int> p[maxn][maxn * maxn];
int ta[maxn], tb[maxn], cnt, tp[maxn], ans[maxn];
void calc(int a, int b) {
	int a1 = p[a][b].first, b1 = p[a][b].second, a2 = a + 1- a1, b2 = b + 1 - b1;
	if(a1 == a) {
		ta[++cnt] = a; tb[cnt] = b; return;
	}
	calc(a1, b1); calc(a2, b2);
}
void getp(int a, int b) {
	if(b == a * (a + 1) / 2) {
		rep(i, 1, a) tp[i] = i;
		return;
	}
	if(b == a + 1) {
		int num = 0;
		for(int i = 2; i <= a; i += 2) tp[++num] = i;
		tp[++num] = 1; num = a;
		for(int i = 3; i <= a; i += 2) tp[num--] = i;
		return;
	}
	tp[1] = 1;
}
int main() {
	p[1][1] = make_pair(1, 1);
	rep(a, 2, N) {
		if(a != 3) p[a][a + 1] = make_pair(a, a + 1);
		p[a][a * (a + 1) / 2] = make_pair(a, a * (a + 1) / 2);
		rep(a1, 2, a - 1) {
			int a2 = a + 1 - a1;
			rep(b1, a1 + 1, a1 * (a1 + 1) / 2) if(p[a1][b1].first)
				rep(b2, a2 + 1, a2 * (a2 + 1) / 2) if(p[a2][b2].first) {
					p[a][b1 + b2 - 1] = make_pair(a1, b1);
					//cout << a << ' ' << b1 + b2 - 1 << endl;
				}
		}
	}
	int Q; scanf("%d", &Q);
	while(Q--) {
		int a, b; scanf("%d%d", &a, &b);
		if(!p[a][b].first) { printf("NO\n"); continue; }
		printf("YES\n");
		cnt = 0;
		calc(a, b);
		int num = 0;
		rep(i, 1, cnt) {
			getp(ta[i], tb[i]);
			if(ta[i] == 1) continue;
			if(!num) rep(j, 1, ta[j]) ans[++num] = tp[j];
			else {
				int tmp = ans[num]; num--;
				rep(j, 1, num) if(ans[j] > tmp) ans[j] += ta[i] - 1;
				rep(j, 1, ta[i]) ans[++num] = tp[j] + tmp - 1;
				int mn = ans[num - ta[i]], mx = ans[num - ta[i] + 1];
				if(mn > mx) swap(mn, mx);
				if(ans[num] < mn || ans[num] > mx) reverse(ans + num - ta[i] + 1, ans + num + 1);
			}
		}
		rep(i, 1, a) printf("%d ", ans[i]);
		printf("\n");
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int N=105;
bool f[N][5555];
int S[N],n,nd,ans[N];
void init(){
	For(i,1,N-1) S[i]=i*(i+1)/2;
	f[0][0]=1;
	For(i,1,N-1) f[i][S[i]]=1;
	For(i,4,N-1) f[i][i+1]=1;
	For(i,1,N-1) For(j,i,S[i]) if (f[i][j]){
		For(k,2,N-i) f[i+k-1][j+S[k]-1]=1;
		For(k,4,N-i) f[i+k-1][j+k]=1;
	}
}
/*
3 1 4 2 5
*/
void construct(int l,int r,int n,int k,int op){
	//printf("con %d %d %d %d\n",l,r,n,k);
	if (k==n*(n+1)/2){
		if (op==0) For(i,l,r) ans[i]=++nd;
		else Rep(i,r,l) ans[i]=++nd;
		return;
	}
	if (k==n){
		for (int i=l+1;i<=r;i+=2) ans[i]=++nd;
		for (int i=l;i<=r;i+=2) ans[i]=++nd;
		if (n%2==1) swap(ans[r],ans[r-2]);
		return;
	}
	For(i,2,n)
		if (k-S[i]+1>0)
			if (f[n-i+1][k-S[i]+1]){
				if (op==0){
					construct(l,r-i+1,n-i+1,k-S[i]+1,1);
					For(j,r-i+2,r) ans[j]=++nd;
				}
				else{
					construct(l+i-1,r,n-i+1,k-S[i]+1,0);
					For(j,l,l+i-2) ans[j]=++nd;
				}
				return;
			}
	For(i,4,n)
		if (k-i>0)
			if (f[n-i+1][k-i]){
				for (int j=r-i+2;j<=r;j+=2) ans[j]=++nd;
				construct(l,r-i+1,n-i+1,k-i,0);
				for (int j=r-i+3;j<=r;j+=2) ans[j]=++nd;
				if (n&1) swap(ans[r-2],ans[r]);
				return;
			}
}
void solve(){
	int n,k; nd=0;
	scanf("%d%d",&n,&k);
	if (!f[n][k]) return puts("NO"),void(0);
	construct(1,n,n,k,0);
	puts("YES");
	For(i,1,n) printf("%d ",ans[i]);
	puts("");
}
int main(){
	init();
	int Q;
	scanf("%d",&Q);
	while (Q--) solve();
}

// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=111;

bool dp[maxn][maxn*maxn/2];
int pre[maxn][maxn*maxn/2],tp[maxn][maxn*maxn/2],q,n,k;

vector<int> all[maxn],ind[maxn];

vector<int> merge(const vector<int>&a,const vector<int>&b)
{
	vector<int> ret;
	int cur=b[0];
	for(auto v:a)ret.pb(v+cur-1);
	if((b[1]>b[0])==(ret[0]<ret[(int)ret.size()-1]))reverse(ret.begin(),ret.end());
	for(auto v:b)if(v<cur)ret.pb(v);else if(v>cur)ret.pb(v+(int)a.size()-1);
	return ret;
}

vector<int> calc(int n,int k)
{
	if(k==n+1)return ind[n];
	else if(k==n*(n+1)/2)return all[n];
	if(tp[n][k]==0)return merge(calc(n-pre[n][k]+1,k-pre[n][k]),ind[pre[n][k]]);
	else return merge(calc(n-pre[n][k]+1,k-pre[n][k]*(pre[n][k]+1)/2+1),all[pre[n][k]]);
}

void solve()
{
	get2(n,k);
	if(n==1)
	{
		puts("YES");
		puts("1");
		return;
	}
	if(dp[n][k])
	{
		puts("YES");
		vector<int> ans=calc(n,k);
		for(auto v:ans)printf("%d ",v);puts("");
	}
	else puts("NO");
}

int main()
{
	for(int i=2;i<=100;i++)
	{
		if(i>3)dp[i][i+1]=1;
		dp[i][i*(i+1)/2]=1;
		for(int j=i+1;j<=i*(i+1)/2;j++)if(dp[i][j])
		{
			for(int k=2;i+k-1<=100;k++)
			{
				dp[i+k-1][j+k*(k+1)/2-1]=1;
				pre[i+k-1][j+k*(k+1)/2-1]=k;
				tp[i+k-1][j+k*(k+1)/2-1]=1;
				if(k>3)
				{
					dp[i+k-1][j+k]=1;
					pre[i+k-1][j+k]=k;
					tp[i+k-1][j+k]=0;
				}
			}
		}
	}
	for(int i=1;i<=100;i++)
	{
		for(int j=1;j<=i;j++)all[i].pb(j);
		if(i<=3)continue;
		if(i%2==0)
		{
			for(int j=2;j<=i;j+=2)ind[i].pb(j);
			for(int j=1;j<=i;j+=2)ind[i].pb(j);
		}
		else
		{
			ind[i]=ind[i-1];
			ind[i].pop_back();
			ind[i].pb(i);
			ind[i].pb(i-2);
		}
	}
	get1(q);
	while(q--)solve();
	return 0;
}