#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n, K;
int getnum(int l, int r)
{
	if (r <= l)
	{
		puts("miaomiaomiao?");
		while (1);
	}
	if (r - l == 1)return 1;
	int mid = (l + r) / 2;
	return getnum(l, mid) + getnum(mid, r) + 1;
}
int a[N];
bool flag;
void solve(int l, int r)
{
	--K;
	if (r - l == 1)return;
	if (K == 0)
	{
		sort(a + l, a + r);
		return;
	}
	if (K >= 2)
	{
		int mid = (l + r) / 2;
		if(a[0] < a[mid])swap(a[0], a[mid]);
		solve(l, mid);
		solve(mid, r);
	}
	else flag = 0;
}
int main()
{
	while (~scanf("%d%d", &n, &K))
	{
		/*
		int totnum = getnum(0, n);
		//printf("totnum = %d\n", totnum);
		if (K > totnum)
		{
			puts("-1");
			continue;
		}
		*/
		for (int i = 0; i < n; ++i)a[i] = i + 1;
		flag = 1;
		solve(0, n);
		if (!flag)
		{
			puts("-1");
			continue;
		}
		for (int i = 0; i < n; ++i)
		{
			printf("%d ", a[i]);
		}puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】
ms(0, n)

mid = (l + r) / 2
len = r - l

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n, K;
int getnum(int l, int r)
{
	if (r <= l)
	{
		puts("miaomiaomiao?");
		while (1);
	}
	if (r - l == 1)return 1;
	int mid = (l + r) / 2;
	return getnum(l, mid) + getnum(mid, r) + 1;
}
int a[N];
bool flag;
void solve(int l, int r)
{
	--K;
	if (r - l == 1)return;
	if (K == 0)
	{
		sort(a + l, a + r);
		return;
	}
	if (K >= 2)
	{
		int mid = (l + r) / 2;
		if(a[0] < a[mid])swap(a[0], a[mid]);
		solve(l, mid);
		solve(mid, r);
	}
	else flag = 0;
}
int main()
{
	while (~scanf("%d%d", &n, &K))
	{
		int totnum = getnum(0, n);
		//printf("totnum = %d\n", totnum);
		if (K >= totnum)
		{
			puts("-1");
			continue;
		}
		for (int i = 0; i < n; ++i)
		{
			a[i] = i + 1;
		}
		flag = 1;
		solve(0, n);
		if (!flag)
		{
			puts("-1");
			continue;
		}
		for (int i = 0; i < n; ++i)
		{
			printf("%d ", a[i]);
		}puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】
ms(0, n)

mid = (l + r) / 2
len = r - l

【分析】

【时间复杂度&&优化】

【数据】

*/


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x, y) memset(x, y, sizeof(x))
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b > a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b < a)a = b; }
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>inline void gadd(T1 &a, T2 b) { a = (a + b) % Z; }
int casenum, casei;
int n, K;
int getnum(int l, int r)
{
	if (r <= l)
	{
		puts("miaomiaomiao?");
		while (1);
	}
	if (r - l == 1)return 1;
	int mid = (l + r) / 2;
	return getnum(l, mid) + getnum(mid, r) + 1;
}
int a[N];
bool flag;
void solve(int l, int r)
{
	--K;
	if (r - l == 1)return;
	if (K == 0)
	{
		sort(a + l, a + r);
		return;
	}
	if (K >= 2)
	{
		int mid = (l + r) / 2;
		if(a[0] < a[mid])swap(a[0], a[mid]);
		solve(l, mid);
		solve(mid, r);
	}
	else flag = 0;
}
int main()
{
	while (~scanf("%d%d", &n, &K))
	{
		/*
		int totnum = getnum(0, n);
		//printf("totnum = %d\n", totnum);
		if (K > totnum)
		{
			puts("-1");
			continue;
		}
		*/
		for (int i = 0; i < n; ++i)a[i] = i + 1;
		flag = 1;
		solve(0, n);
		if (!flag || K)
		{
			puts("-1");
			continue;
		}
		for (int i = 0; i < n; ++i)
		{
			printf("%d ", a[i]);
		}puts("");
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】
ms(0, n)

mid = (l + r) / 2
len = r - l

【分析】

【时间复杂度&&优化】

【数据】

*/


#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n, k, arr[maxn];
void unsort(int l, int r)
{
    if(r-l<=1)return;
    int mid=(l+r)/2;
    if(k>0)
    {
        k-=2;
        swap(arr[mid-1], arr[mid]);
        unsort(l, mid);
        unsort(mid, r);
    }
}
int main()
{
    scanf("%d%d", &n, &k);
    if(k%2==0)
    {
        printf("%d\n", -1);
        return 0;
    }
    for(int i=0; i<n; i++)
        arr[i]=i+1;
        k--;
    unsort(0, n-1);
    if(k==0)
    for(int i=0; i<n; i++)
        printf("%d ", arr[i]);
        else printf("%d", -1);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n, k, arr[maxn];
void unsort(int l, int r)
{
    int mid=(l+r)>>1;
    if(k>0&&mid!=r)
    {
        swap(arr[mid], arr[mid+1]);
        k--;
        unsort(l, mid);
        unsort(mid, r);
    }
}
int main()
{
    scanf("%d%d", &n, &k);
    if(k%2==0)
    {
        printf("%d\n", -1);
        return 0;
    }
    for(int i=1; i<=n; i++)
        arr[i]=i;
    unsort(1, n);
    if(k==0)
    for(int i=1; i<=n; i++)
        printf("%d ", arr[i]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n, k, arr[maxn];
void unsort(int l, int r)
{
    if(r-l<=1)return;
    int mid=(l+r)/2;
    if(k>0)
    {
        k-=2;
        swap(arr[mid-1], arr[mid]);
        unsort(l, mid);
        unsort(mid, r);
    }
}
int main()
{
    scanf("%d%d", &n, &k);
    if(k%2==0)
    {
        printf("%d\n", -1);
        return 0;
    }
    for(int i=1; i<=n; i++)
        arr[i]=i;
        k--;
    unsort(1, n);
    if(k==0)
    for(int i=1; i<=n; i++)
        printf("%d ", arr[i]);
        else printf("%d", -1);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n, k, arr[maxn];
void unsort(int l, int r)
{
    if(r-l<1)return;
    int mid=(l+r)/2;
    if(k>0)
    {
        swap(arr[mid-1], arr[mid]);
        k--;
        unsort(l, mid);
        unsort(mid, r);
    }
}
int main()
{
    scanf("%d%d", &n, &k);
    if(k%2==0)
    {
        printf("%d\n", -1);
        return 0;
    }
    for(int i=1; i<=n; i++)
        arr[i]=i;
    unsort(1, n);
    if(k==0)
    for(int i=1; i<=n; i++)
        printf("%d ", arr[i]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n, k, arr[maxn];
void unsort(int l, int r)
{
    if(r-l<=1)return;
    int mid=(l+r)/2;
    if(k>0)
    {
        k-=2;
        swap(arr[mid-1], arr[mid]);
        unsort(l, mid);
        unsort(mid, r);
    }
}
int main()
{
    scanf("%d%d", &n, &k);
    if(k%2==0)
    {
        printf("%d\n", -1);
        return 0;
    }
    for(int i=0; i<n; i++)
        arr[i]=i+1;
        k--;
    unsort(0, n);
    if(k==0)
    for(int i=0; i<n; i++)
        printf("%d ", arr[i]);
        else printf("%d", -1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] >= k) solve(l, mid, k);
    else
    {
        for(int i = l; i <= mid; i++) a[i] = l + mid - i;
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = f[i/2] + f[i-i/2] + 2;
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] >= k) solve(l, mid, k);
    else
    {
        for(int i = l; i <= r; i++) a[i] = r + l - i;
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = min(200001, f[i/2] + f[i-i/2] + 2);
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] > k) solve(l, mid, k);
    else
    {
        for(int i = l; i <= mid; i++) a[i] = l + mid - i;
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = min(200001, f[i/2] + f[i-i/2] + 2);
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] > k) solve(l, mid, k);
    else
    {
        for(int i = l; i <= r; i++) a[i] = r + l - i;
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = min(200001, f[i/2] + f[i-i/2] + 2);
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[mid], a[mid+1]); return;}
    if(f[mid-l+1] >= k) solve(l, mid, k);
    else
    {
        solve(l, mid, f[mid-l+1]);
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = f[i/2] + f[i-i/2] + 2;
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] >= k) solve(l, mid, k);
    else
    {
        for(int i = l; i <= mid; i++) a[i] = l + mid - i;
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = min(200001, f[i/2] + f[i-i/2] + 2);
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int f[maxn], a[maxn];

void solve(int l, int r, int k)
{
    if(!k) return;
    k -= 2;
    int mid = (l + r - 1) / 2;
    if(k == 0) {swap(a[l], a[mid+1]); return;}
    if(f[mid-l+1] >= k) solve(l, mid, k);
    else
    {
        solve(l, mid, f[mid-l+1]);
        solve(mid + 1, r, k - f[mid-l+1]);
    }
}

int main(void)
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) a[i] = i;
    for(int i = 2; i <= n; i++)
        f[i] = f[i/2] + f[i-i/2] + 2;
    k--;
    if(k % 2 || f[n] < k) puts("-1");
    else
    {
        solve(1, n, k);
        for(int i = 1; i <= n; i++) printf("%d ", a[i]);
        puts("");
    }
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%lld",&x)
#define SI size()
#define pf(x) printf("%lld",&x)
#define R return
#define C continue
#define ll long long
#define ull unsigned long long
#define pb push_back
#define S second
#define F first
#define mem memset
using namespace std;

int a[1000030],n,k,ans=1;

void solve(int l,int r){
    if(l==r) R;
    if(ans==k){
        cout << l << " " << r << endl;
        sort(a+l,a+r);
        R;
    }
    ans+=2;
    ll mid=(l+r)/2;
    solve(l,mid);
    solve(mid,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    int x=n,y=k;
    y--;
    while(x>0){
        x/=2;
        y--;
    }
    if(y>0){cout << -1;R 0;}
    for(int i=0;i<n;i++) a[i]=n-i;
    solve(0,n);
    for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%lld",&x)
#define SI size()
#define pf(x) printf("%lld",&x)
#define R return
#define C continue
#define ll long long
#define ull unsigned long long
#define pb push_back
#define S second
#define F first
#define mem memset
using namespace std;

int a[1000030],n,k,ans=1;

void solve(int l,int r){
    if(l==r) R;
    if(ans==k){
        sort(a+l,a+r);
        R;
    }
    ans+=2;
    ll mid=(l+r)/2;
    solve(l,mid);
    solve(mid,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    int x=n,y=k;
    y--;
    while(x>0){
        x/=2;
        y--;
    }
    if(y>0){cout << -1;R 0;}
    for(int i=0;i<n;i++) a[i]=n-i;
    solve(0,n);
    for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%lld",&x)
#define SI size()
#define pf(x) printf("%lld",&x)
#define R return
#define C continue
#define ll long long
#define ull unsigned long long
#define pb push_back
#define S second
#define F first
#define mem memset
using namespace std;

int a[1000030],w[1000030],n,k,ans=1;

void solve(int l,int r){
    if(l==r) R;
    if(ans==k){
        r=min(r,n-1);
        sort(a+l,a+r+1);
        R;
    }
    ans+=2;
    ll mid=(l+r)/2;
    solve(l,mid);
    solve(mid+1,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;i++) a[i]=n-i;
    solve(0,n);
    if(ans!=k){cout << -1;R 0;}
    for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%lld",&x)
#define SI size()
#define pf(x) printf("%lld",&x)
#define R return
#define C continue
#define ll long long
#define ull unsigned long long
#define pb push_back
#define S second
#define F first
#define mem memset
using namespace std;

int a[1000030],w[1000030],n,k,ans=1;

void solve(int l,int r){
    if(l+1==r){R;}
    if(ans==k){
        sort(a+l,a+r);
        R;
    }
    ans+=2;
    ll mid=(l+r)/2;
    solve(l,mid);
    solve(mid,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;i++) a[i]=n-i;
    solve(0,n);
    if(ans!=k){cout << -1;R 0;}
    for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
#define sf(x) scanf("%lld",&x)
#define SI size()
#define pf(x) printf("%lld",&x)
#define R return
#define C continue
#define ll long long
#define ull unsigned long long
#define pb push_back
#define S second
#define F first
#define mem memset
using namespace std;

int a[1000030],w[1000030],n,k,ans=1,ans1=1;

void solve(int l,int r){
    if(l==r) R;
    if(ans==k){
        sort(a+l,a+r);
        R;
    }
    ans+=2;
    ll mid=(l+r)/2;
    solve(l,mid);
    solve(mid+1,r);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i=0;i<n;i++) a[i]=n-i;
    solve(0,n);
    if(ans!=k){cout << -1;R 0;}
    for(int i=0;i<n;i++) cout << a[i] << " ";
    return 0;
}


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

int n, k;
vector<pair<int,int> > resp;

vector<pair<int,int> > bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {{l,r}};
	}
	vector<pair<int,int> >	aux1 = bt(l,(r+l)/2,cant/2 - (1+cant/2)%2);
	vector<pair<int,int> > aux2 = bt((r+l)/2,r,cant/2 + (1+cant/2)%2);
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=it.first+1; i<=it.second; ++i){
				cout<<n--<<" \n"[n==1];
			}
		}
	}
	return 0;
}


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

int n, k;
vector<int> resp;

vector<int> bt(int l=n, int cant=k){
	if(cant==1){
		return {l};
	}
	vector<int> aux1 = bt(l/2, cant/2 - (1+(cant/2))%2);
	vector<int>	aux2 = bt(l/2 + l%2, cant/2 + (1+(cant/2))%2);
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
map< pair<int,int> , vector<int> > mp;
vector<int> resp;

vector<int> bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {r-l};
	}
	if(r-l==1){
		return {};
	}
	if(mp.find({r-l,cant})!=mp.end()){
		return mp[{r-l,cant}];
	}
	vector<int> aux1;
	vector<int> aux2;
	for(int i=1; i<=cant-2; ++i){
		aux1 = bt(l,(r+l)/2,i);
		if(!aux1.empty()){
			aux2 = bt((r+l)/2,r,cant-1-i);
			if(!aux2.empty()){
				break;
			}
		}
	}
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	resp = bt();
	if(resp.empty()){
		cout<<"-1\n";
	}
	else{
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
vector<pair<int,int> > resp;

vector<pair<int,int> > bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {{l,r}};
	}
	vector<pair<int,int> >	aux1 = bt(l,(r+l)/2,cant/2 - (1+cant/2)%2);
	vector<pair<int,int> > aux2 = bt((r+l)/2,r,cant/2 + (1+cant/2)%2);
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=n-it.second+1; i<=n-it.first; ++i){
				cout<<i<<" \n"[i==n-it.first && n-it.second+1==1];
			}
		}
	}
	return 0;
}


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

int n, k;
vector<int> resp;

vector<int> bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {r-l};
	}
	if(r-l==1){
		return {};
	}
	vector<int> aux1, aux2;
	if((cant/2)%2){
		aux1 = bt(l,(r+l)/2,cant/2);
		aux2 = bt((r+l)/2,r,cant/2);
	}
	else{
		aux1 = bt(l,(r+l)/2,cant/2-1);
		aux2 = bt((r+l)/2,r,cant/2+1);
	}
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
vector<int> resp;

vector<int> bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {r-l};
	}
	if(r-l==1){
		return {};
	}
	vector<int> aux1 = bt(l,(r+l)/2,1);
	vector<int> aux2 = bt((r+l)/2,r,cant-2);
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
vector<int> resp;

vector<int> bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {r-l};
	}
	if(r-l==1){
		return {};
	}
	vector<int> aux1, aux2;
	if((cant/2)%2){
		aux1 = bt(l,(r+l)/2,cant/2);
		aux2 = bt((r+l)/2,r,cant/2);
	}
	else{
		aux1 = bt(l,(r+l)/2,cant/2+1);
		aux2 = bt((r+l)/2,r,cant/2-1);
	}
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
map< pair<int,int> , vector<int> > mp;
vector<int> resp;

vector<int> bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {r-l};
	}
	if(r-l==1){
		return {};
	}
	if(mp.find({r-l,cant})!=mp.end()){
		return mp[{r-l,cant}];
	}
	vector<int> aux1;
	vector<int> aux2;
	for(int i=1; i<=cant-1; ++i){
		aux1 = bt(l,(r+l)/2,i);
		if(!aux1.empty()){
			aux2 = bt((r+l)/2,r,cant-i);
			if(!aux2.empty()){
				break;
			}
		}
	}
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	resp = bt();
	if(resp.empty()){
		cout<<"-1\n";
	}
	else{
		for(auto it : resp){
			for(int i=n-it+1; i<=n; ++i){
				cout<<i<<" \n"[(n-it)==0 && i==n];
			}
			n-=it;
		}
	}
	return 0;
}


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

int n, k;
vector<pair<int,int> > resp;

vector<pair<int,int> > bt(int l=0, int r=n, int cant=k){
	if(cant==1){
		return {{l,r}};
	}
	vector<pair<int,int> >	aux1 = bt(l,(r+l)/2,cant/2 - (1+cant/2)%2);
	vector<pair<int,int> > aux2 = bt((r+l)/2,r,cant/2 + (1+cant/2)%2);
	while(!aux2.empty()){
		aux1.push_back(aux2.back());
		aux2.pop_back();
	}
	return aux1;
}

int main(){
	cin>>n>>k;
	if(k%2==0){
		cout<<"-1\n";
	}
	else if(2*n-1<k){
		cout<<"-1\n";
	}
	else{
		resp = bt();
		sort(resp.begin(),resp.end());
		for(auto it : resp){
			for(int i=n-it.second+1; i<=n-it.first; ++i){
				cout<<i<<" \n"[i==n-it.first && n-it.second+1==1];
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 100005
using namespace std;
int N,K;
int temp;
int num[MAXN];
void merge(int l,int r){
	if(K<=0 || l+1>=r) return ;
	K-=2;
	int mid=(l+r)>>1;

	temp=num[mid-1];
	num[mid-1]=num[mid];
	num[mid]=temp;

	merge(l,mid);
	merge(mid,r);

	return ;
}
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++) num[i]=i+1;

	if(K%2==0 || K>2*N-1) cout<<-1;
	else
	{
		K--;
		merge(0,N);
		for(int i=0;i<N;i++)
			printf("%d ",num[i]);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 100005
using namespace std;
int N,K;
int mid;
int temp;
int num[MAXN];
void merge(int l,int r){
	if(K<=0) return ;
	if(l+1>=r) return ;
	K-=2;
	mid=(l+r)/2;

	temp=num[mid-1];
	num[mid-1]=num[mid];
	num[mid]=temp;

	merge(l,mid);
	merge(mid,r);

	return ;
}
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++) num[i]=i+1;

	if(K%2==0 || K>2*N-1) cout<<-1;
	else
	{
		K--;
		merge(0,N);
		for(int i=0;i<N;i++)
			printf("%d ",num[i]);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 100005
using namespace std;
int N,K;
int mid;
int num[MAXN];
void merge(int l,int r){
	if(l+1>=r || !K) return ;
	K-=2;
	mid=(l+r)/2;
	swap(num[mid-1],num[mid]);
	merge(l,mid);
	merge(mid,r);
}
int main(){
	cin>>N>>K;
	for(int i=1;i<=N;i++) num[i]=i;

	if(K%2==0) cout<<-1;
	else
	{
		K--;
		merge(1,N);
		if(K) cout<<-1;
		else
			for(int i=1;i<=N;i++)
				printf("%d ",num[i]);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 100005
using namespace std;
int N,K;
int mid;
int num[MAXN];
void merge(int l,int r,int k){
	if(k<=0) return ;
	mid=(l+r)/2;
	int n0=mid-l;
	swap(num[mid-1],num[mid]);

	k-=2;
	if(k<=2*(n0-1)) merge(l,mid,k);
	else
	{
		merge(l,mid,2*(n0-1));
		merge(mid,r,k-2*(n0-1));
	}
	return ;
}
int main(){
	cin>>N>>K;
	for(int i=1;i<=N;i++) num[i]=i;

	if(K%2==0 || K>2*N-1) cout<<-1;
	else
	{
		K--;
		merge(1,N,K);
		for(int i=1;i<=N;i++)
			printf("%d ",num[i]);
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#define MAXN 100005
using namespace std;
int N,K;
int temp;
int mid;
int num[MAXN];
void merge(int l,int r){
	if(K<=0 || l+1>=r) return ;
	K-=2;
	mid=(l+r)>>1;

	temp=num[mid-1];
	num[mid-1]=num[mid];
	num[mid]=temp;

	merge(l,mid);
	merge(mid,r);

	return ;
}
int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++) num[i]=i+1;

	if(K%2==0 || K>2*N-1) cout<<-1;
	else
	{
		K--;
		merge(0,N);
		for(int i=0;i<N;i++)
			printf("%d ",num[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,k;
int a[100100];
void msort(int l,int r)
{
	if(k>=2&&l+1<r)
	{
		k-=2;
		int mid=(l+r)/2;
		swap(a[mid],a[mid-1]);
		msort(l,mid);msort(mid,r);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	if(k%2==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n)a[i]=i;
	k--;
	msort(0,n);
	if(k)cout<<-1<<endl;
	else{
		rep(i,n)cout<<a[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,k;
int a[100100];
void msort(int l,int r)
{
	int mid=l+r>>1;
	if(k>=2&&l<=r)
	{
		k-=2;
		swap(a[mid],a[mid-1]);
		msort(l,mid);msort(mid,r);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	if(!k%2)
	{
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n)a[i]=i;
	k--;
	msort(0,n);
	if(k)cout<<-1<<endl;
	else{
		rep(i,n)cout<<a[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,k;
int a[100100];
void msort(int l,int r)
{
	int mid=l+r>>1;
	if(k>=2&&l<=r)
	{
		k-=2;
		swap(a[mid],a[mid-1]);
		msort(l,mid-1);msort(mid+1,r);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	if(!k%2)
	{
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n)a[i]=i;
	k--;
	msort(0,n);
	if(k)cout<<-1<<endl;
	else{
		rep(i,n)cout<<a[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,k;
int a[100100];
void msort(int l,int r)
{
	int mid=l+r>>1;
	if(k>=2&&l<=r)
	{
		k-=2;
		swap(a[mid],a[mid-1]);
		msort(l,mid-1);msort(mid,r+1);
	}
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	if(!k%2)
	{
		cout<<-1<<endl;
		return 0;
	}
	rep(i,n)a[i]=i;
	k--;
	msort(0,n);
	if(k)cout<<-1<<endl;
	else{
		rep(i,n)cout<<a[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define heap priority_queue
using namespace std;
const ll maxn=200000+5;
const ll inf=9e17;
ll a[maxn],n,k;
inline void buildtree(ll l,ll r)
{
	if(l>r)
		return;
	ll mid=(l+r)/2;
	if(k)
	{
		k-=2;
		swap(a[mid-1],a[mid]);
		buildtree(l,mid);
		buildtree(mid+1,r);
	}
	return;
}
int main()
{
	cin>>n>>k;
	if(k==0||k>2*n-1||!(k&1))
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n;i++)
		a[i]=i;
	--k;
	buildtree(1,n);
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define heap priority_queue
using namespace std;
const ll maxn=200000+5;
const ll inf=9e17;
ll a[maxn],n,k;
inline void buildtree(ll l,ll r)
{
	if(l>=r-1)
		return;
	ll mid=(l+r)/2;
	if(k)
	{
		k-=2;
		swap(a[mid-1],a[mid]);
		buildtree(l,mid);
		buildtree(mid,r);
	}
	return;
}
int main()
{
	cin>>n>>k;
	if((k==0)||(k>2*n-1)||(!(k&1)))
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n;i++)
		a[i]=i;
	--k;
	buildtree(1,n);
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define heap priority_queue
using namespace std;
const ll maxn=200000+5;
const ll inf=9e17;
ll a[maxn],n,k;
inline void buildtree(ll l,ll r)
{
	if(l>r)
		return;
	ll mid=(l+r)/2;
	if(k)
	{
		k-=2;
		swap(a[mid-1],a[mid]);
		buildtree(l,mid);
		buildtree(mid+1,r);
	}
	return;
}
int main()
{
	cin>>n>>k;
	if(k==0||k>2*n-1||!(k&1))
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=0;i<n;i++)
		a[i]=i+1;
	--k;
	buildtree(0,n-1);
	for(int i=0;i<n;i++)
		cout<<a[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define heap priority_queue
using namespace std;
const ll maxn=200000+5;
const ll inf=9e17;
ll a[maxn],n,k;
inline void buildtree(ll l,ll r)
{
	if(l>r)
		return;
	ll mid=(l+r)/2;
	if(k)
	{
		k-=2;
		swap(a[mid-1],a[mid]);
		buildtree(l,mid);
		buildtree(mid,r);
	}
	return;
}
int main()
{
	cin>>n>>k;
	if((k==0)||(k>2*n-1)||(!(k&1)))
	{
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n;i++)
		a[i]=i;
	--k;
	buildtree(1,n);
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return 0;
}


#include <stdio.h>

int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		int n;
		int answer = 1;
		scanf("%d" ,&n);
		char temp[n];
		for (int j = 0; j < n; j++) {
			temp[j] = '0';
		}
		for (int j = 0; j < n; j++) {
			char row[n];
			scanf("%s", row);
			for (int k = 0; k < n-1; k++) {
				if (temp[k] == '1') {
					if (row[k] == '0') {
						answer = 0;
					}
				}
				temp[k] = '0';
				if (row[k] == '1') {
					if (row[k+1] == '0') {
						temp[k] = '1';
					}
				}
			}
		}
		if (answer == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
}


#include <stdio.h>

int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		int n;
		int answer = 1;
		scanf("%d" ,&n);
		char temp[n];
		for (int j = 0; j < n; j++) {
			temp[j] = '0';
		}
		for (int j = 0; j < n; j++) {
			char row[n];
			scanf("%s", row);
			for (int k = 0; k < n; k++) {
				if (temp[k] == '1') {
					if (row[k] == '0') {
						answer = 0;
					}
				}
				temp[k] = '0';
				if (row[k] == '1') {
					if (row[k+1] == '0') {
						temp[k] = '1';
					}
				}
			}
		}
		if (answer == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
}


#include <stdio.h>

int main() {
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		int n;
		int answer = 1;
		scanf("%d" ,&n);
		char temp[n];
		for (int j = 0; j < n; j++) {
			temp[j] = '0';
		}
		for (int j = 0; j < n-1; j++) {
			char row[n];
			scanf("%s", row);
			for (int k = 0; k < n; k++) {
				if (temp[k] == '1') {
					if (row[k] == '0') {
						answer = 0;
					}
				}
				temp[k] = '0';
				if (row[k] == '1') {
					if (row[k+1] == '0') {
						temp[k] = '1';
					}
				}
			}
		}
		if (answer == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int i,t,j,k,n;
    scanf("%d",&t);
    for(i=0;i<t;i++){
        int flag=1;
        scanf("%d", &n);
        char arr[n][n];
        for(j=0;j<n;j++){

                scanf("%s", arr[j]);

        }
        for(j=0;j<n-1;j++){
            for(k=0;k<n-1;k++){
                if(arr[j][k]=='1'){
                        if(arr[j][k+1]=='1' || arr[j+1][k]=='1'){continue;}
                        else{flag=0;break;}
                }
                else{continue;}
           }
            if(flag==0){break;}
        }
        if(flag==1){printf("YES\n");}
        else{printf("NO\n");}
    }
}


#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int t, n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n][n];
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				cin>> a[i][j];
			}
		}
		int flag=0;
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j;
							cout<<"NO";
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
				continue;
		cout<<"YES";
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
//using namespace std;
int main()
{
	int t, n;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		int a[n][n], i, j, flag=0;
		for(i= 0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				scanf("%d", &a[i][j]);
			}
		}
		for(i= 0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endl;
							printf("NO\n");
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
			continue;
		printf("YES\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
//using namespace std;
int main()
{
	int t, n;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		int a[n][n], i, j, flag=0;
		char x[n];
		for(i= 0; i<n; i++)
		{
			scanf("%s", x);
			for(j=0; j<n; j++)
			{
				a[i][j] = x[j]-'0';
			}
		}
		for(i= 0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endl;
							printf("NO\n");
							flag=1;
							break;
						}
					}
				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
			continue;
		printf("YES\n");
	}
	return 0;
}


#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int t, n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n][n];
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				cin>> a[i][j];
			}
		}
		int flag=0;
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endlzz;
							cout<<"NO";
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
				continue;
		cout<<"YES";
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
//using namespace std;
int main()
{
	int t, n;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		int a[n][n], i, j, flag=0;
		char x[n];
		for(i= 0; i<n; i++)
		{
			scanf("%s", x);
			for(j=0; j<n; j++)
			{
				a[i][j] = x[j]-'0';
			}
		}
		for(i= 0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endl;
							printf("NO\n");
							flag=1;
							break;
						}
					}
				}
			}
			if(flag==1)
				break;
		}

		if(flag==1)
			continue;
		printf("YES\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
//using namespace std;
int main()
{
	int t, n;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &n);
		int a[n][n], i, j, flag=0;
		char x[n];
		for(i= 0; i<n; i++)
		{
			scanf("%s", x);
			for(j=0; j<n; j++)
			{
				a[i][j] = x[j];
			}
		}
		for(i= 0; i<n; i++)
		{
			for(j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endl;
							printf("NO\n");
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
			continue;
		printf("YES\n");
	}
	return 0;
}


#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int t, n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n][n];
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				cin>> a[i][j];
			}
		}
		int flag=0;
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							//cout<<" "<<i<<" "<<j<<endl;
							cout<<"NO";
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
				continue;
		cout<<"YES";
	}
	return 0;
}


#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int t, n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n][n];
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				cin>> a[i][j];
			}
		}
		int flag=0;
		for(int i= 0; i<n; i++)
		{
			for(int j=0; j<n; j++)
			{
				if(i<n-1 && j< n-1){
					if(a[i][j]==1){
						if(a[i+1][j]!=1 && a[i][j+1]!=1){
							cout<<"NO";
							flag=1;
							break;
						}
					}

				}
			}
			if(flag==1)
				break;
		}
		if(flag==1)
				continue;
		cout<<"YES";
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int T;
    scanf("%d",&T);
    while(T>0)
    {
       int n , i , j ;
       scanf("%d",&n);
       char line[n+1];
       int a[n][n];

       for(i=0 ; i<n ; i++ )
       {
           scanf("%s",line);
           line[n]='\0';
           for(j=0 ; j<n ; j++)
           {
              a[i][j]=line[j]-48;
           }
       }
       int found=0;
       for(i=0 ; (i<n)&&(!found) ; i++)
       {
           for(j=0 ; (j<n)&&(!found) ; j++)
           {
               if(a[i][j]==1)
               {
                    if((j<n-1)&&(a[i][j+1]==0)&&(i<n-1)&&(a[i+1][j]==0)) found=1;
               }
           }
       }
       if(found) printf("NO\n");
       else printf("YES\n");

        T--;
    }
    return 0;
}


#include <stdio.h>
#include<stdlib.h>
#include<string.h>

char a[55][55];

int main()
{
    int i,j,n,t;
    scanf("%d",&t);
    for(int pro = 1 ; pro <= t ; pro++)
    {
 scanf("%d",&n);
        for(i=1; i<=n; i++)
            scanf("%s",a[i]+1);
        if(n==1)
        {
            printf("YES\n");
            continue;
        }
        int dp = 0;
        for(i=n-1; i>=1; i--) {
            for(j=n-1; j>=1; j--)
                if(a[i][j]=='1')
                {
                    if(a[i+1][j]=='1')
                        dp=1;
                    else if(a[i][j+1]=='1')
                        dp = 1;
                    else
                    {
                        dp=0;
                        break;
                    }
                }
            if(a[i][j]=='1' && !dp)
                break;
        }
        if(a[i][j]=='1' && !dp)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, z = 0;
		scanf("%d", &n);
		char s[51][53];

		for (int i = 0; i<n; i++)
		{
			scanf("%s", s[i]);
		}

		for (int i = 0; i<n - 1; i++)
		{
			for (int j = 0; j<n - 1; j++)
			{
				if (s[i][j] == '1')
				{
					if (s[i + 1][j] == '1' || s[i][j + 1] == '1')
					{
						continue;
					}
					else
					{
						z = 1;
						printf("NO\n");
						break;
					}
				}

			}
			if (z == 1)
			{
				break;
			}
		}
		if (z == 0)
		{
			printf("YES\n");
		}
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define findmax(a,b) (a)>(b)?(a):(b)
#define findmin(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}

int main() {
	//inout;

	int t;
	scanf("%d", &t);
	while(t--){

		int n;

		scanf("%d", &n);

		char a[n][n+1];

		for(int i = 0; i < n; i++){
			scanf("%s", a[i]);
		}

		for(int i = 0; i + 1 < n; i++){
			for(int j =0; j + 1 < n; j++){
				if(a[i][j] == '1' && a[i][j+1] == '0' && a[i+1][j] == '0'){
					puts("NO");
					goto a;
				}
			}
		}
		puts("YES");
		a:;
	}
}


#include <stdio.h>
int main()
{
    int t,n,i,j,flag;
    scanf("%d",&t);
    while(t)
    {
        scanf("%d",&n);
        char a[n][n];
        for(i=0;i<n;i++)
        {
        for(j=0;j<n;j++)
        {
        scanf(" %c",&a[i][j]);
        }
        }
        flag=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(a[i][j]=='1')
                {
                    if(i==n-1||j==n-1)
                    continue;
                    else if(a[i+1][j]=='1'||a[i][j+1]=='1')
                    continue;
                    else
                    {
                        flag=1;
                        printf("NO\n");
                        break;
                    }
                }
            }
            if(flag==1)
            break;
        }
        if(flag!=1)
        printf("YES\n");
        t--;
    }
}


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>

typedef long long ll;
typedef unsigned long long ull;
#define MINN(x,y) ((x)<(y)?(x):(y))
#define MAXN(x,y) ((x)>(y)?(x):(y))
#define ABSN(x)   (((x)>0)?(x):(0-(x)))
const ll MOD = 1000000007;
const ll MOD1 = 998244353;

int readint()
{
	int res = 0;
	char c = 0;
	while (!isdigit(c))
		c = getchar();
	while (isdigit(c))
		res = res * 10 + c - '0', c = getchar();
	return res;
}

int cmpIn(const void *a, const void *b){
    return *(int *)a-*(int *)b;
}

int cmpDe(const void *a, const void *b){
    return *(int *)b-*(int *)a;
}

void solve()
{
    int  n, m;
    scanf("%d",&n);
    int dp[n][n];
    //scanf("%d",&m);
    for(int i=0;i<n;i++){
        char m;
        m=getchar();
        for(int j=0;j<n;j++){
            dp[i][j]=0;
            char c=getchar();
            dp[i][j]=(c-'0');
            //scanf("%d",&dp[i][j]);
        }
    }
    /*
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            printf("%d ",dp[i][j]);
        }
        printf("\n");
    }
    */
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            if(dp[i][j]==0){
                continue;
            }
            if((i!=(n-1))&&(j!=(n-1))&&(dp[i][j+1]==0&&dp[i+1][j]==0)){
                printf("NO\n");
                return;
            }
        }
        for(int j=i+1;j<n;j++){
            if(dp[j][i]==0){
                continue;
            }
            if((i!=(n-1))&&(j!=(n-1))&&(dp[j][i+1]==0&&dp[j+1][i]==0)){
                printf("NO\n");
                return;
            }
        }
    }
    //int ans=0;
    printf("YES\n");
    return;
}

int main()
{
    int n;
    scanf("%d",&n);
    while (n--) {
        solve();
    }
    return 0;
}


//░░░
// ░ anzim bin nasir
// ░
#include<stdio.h>
int main()
{
    int t,n,i,check,j;
    char a[50][50];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        check=0;
        for(i=0;i<n;i++)
        scanf("%s",&a[i]);
        for(i=0;i<n-1;i++)
        {
            for(j=0;j<n-1;j++)
            {
                if(a[i][j]=='1')
                {
                    if(a[i+1][j]=='0'&&a[i][j+1]=='0')
                        {
                            check=1;
                            break;
                        }
                }
            }
        }
        if(check)
        printf("NO\n");
        else
        printf("YES\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int t, n, row, col, i, j, test=1, a[52][52];
    char str[52][52], ch;
    scanf("%d", &t);
    while(t--){
        scanf("%d", &n);

        for(i=0; i<n; i++){
            scanf("%s", str[i]);
            for(j=0; j<n; j++){
                ch = str[i][j];
                a[i][j] = ch - '0';
            }
        }
        /*for(i=0; i<n; i++){
            for(j=0; j<n; j++){
                printf("%d ", a[i][j]);
            }
            printf("\n");
        }*/

        for(row=0; row<n; row++){
            for(col=0; col<n; col++){
                if(a[row][col] == 1)
                {
                    if(row==n-1 || col==n-1){
                        test = 1;
                    }
                    else if(a[row+1][col]==1 || a[row][col+1]==1){
                        test =1 ;
                    }
                    else{
                        test =0;
                        break;
                    }
                }
                if(!test) break;
            }
        }
        printf("%s\n", test==1 ? "YES" : "NO");
        test = 1;
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int t, n, row, col, i, j, test=1, a[52][52];
    char str[52][52], ch;
    scanf("%d", &t);
    while(t--){
        scanf("%d", &n);

        for(i=0; i<n; i++){
            scanf("%s", str[i]);
            for(j=0; j<n; j++){
                ch = str[i][j];
                a[i][j] = ch - '0';
            }
        }
        //for(i=0; i<n; i++) for(j=0; j<n; j++) printf("%d ", a[i][j]);
        for(row=0; row<n-1; row++){
            for(col=0; col<n-1; col++){
                if(a[row][col] == 1)
                {
                    if(a[row+1][col]==0 && a[row][col+1]==0){
                        test = 0 ;
                        break;
                    }
                }
            }
            if(!test) break;
        }
        printf("%s\n", test ? "YES" : "NO");
        test = 1;
    }

    return 0;
}


#include <stdio.h>

int main(void)
    {
        int t;
        scanf("%d",&t);
        while (t--)
            {
                int n;
                scanf("%d%*c",&n);
                char s[n][n];
                int count;
                for (count = 0; count < n; count++) gets(s[count]);
                int count1;
                int check = 1;
                for (count = 0; count < n; count++)
                {
                for (count1 = 0; count1< n; count1++)
                    {
                        if (s[count][count1] == '1')
                            {
                                if (count == n-1 || count1 == n-1)
                                continue;
                                else
                                    {
                                        if (s[count+1][count1]=='0'&&s[count][count1+1]=='0')
                                            {
                                                printf("NO\n");
                                                check = 0;
                                                break;
                                            }
                                        else continue;
                                    }

                            }
                    }
                    if (check == 0) break;
                }
                if (check == 1) printf("YES\n");
            }
    }


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int main()
{
    int t,z;
    scanf("%d",&t);
    for(z=0;z<t;z++)
    {
        int n,m,i,k,j=0;
        scanf("%d",&n);
        char S[n][n];
        for(i=0;i<n;i++)
        {
            scanf("%s",&S[i]);
        }
        for(i=0;i<n;i++)
        {
            for(k=0;k<n;k++)
            {
                if(i==n-1||k==n-1)
                {
                    continue;
                }
                else if(S[i][k]=='1')
                {
                    if(S[i+1][k]=='1'||S[i][k+1]=='1')
                    {
                        continue;
                    }
                    else
                    {
                        j=1;
                        break;
                    }
                }
            }
            if(j==1)
            {
                break;
            }
        }
        if(i==n)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}


var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = new Array(N);
		var isOK = true;
		for(var j = 0; j < N; j++){
			list[j] = nextCharArray();
		}
		for(var j = 0; j < N; j++){
			for(var k = 0; k < N; k++){
				if(list[j][k] == "1"){
					var migi = true;
					var sita = true;
					if(j < N - 1){
						if(list[j + 1][k] == "0"){
							sita = false;
						}
					}
					if(k < N - 1){
						if(list[j][k + 1] == "0"){
							migi = false;
						}
					}
					if(!migi && !sita){
						isOK = false;
					}
				}
			}
		}
		if(isOK){
			output[i] = "YES";
		}else{
			output[i] = "NO";
		}
	}
	myout(myconv(output,9));
}


using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n_tc = Convert.ToInt32(Console.ReadLine());
        for (int tc = 0; tc < n_tc; ++tc)
        {
            int side = Convert.ToInt32(Console.ReadLine());
            string instr = "";
            for (int i = 0; i < side; ++i)
            {
                instr += Console.ReadLine() + " ";
            }
            instr += "0";
            for (int i = 0; i < side-1; ++i)
                instr += " 0";
            int[] polygon = instr.Split().Select(int.Parse).ToArray();

            bool succeed = true;
            for (int i = 0; i < side*2; ++i)
            {
                for(int j = 0; j < side*side; ++j)
                {
                    if (polygon[j] == 1)
                    {
                        if (polygon[j + side] == 2 || polygon[j + 1] == 2 || j >= side*3 || j%side == side - 1)
                        {
                            polygon[j] = 2;

                        }
                    }
                }
            }
            for (int i = 0; i<side*side; ++i)
            {
                if(polygon[i]== 1)
                {
                    succeed = false;
                }
            }
            if (succeed == false)
                Console.WriteLine("NO");
            else
                Console.WriteLine("YES");

        }
    }
}


using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n_tc = Convert.ToInt32(Console.ReadLine());
        for (int tc = 0; tc < n_tc; ++tc)
        {
            int side = Convert.ToInt32(Console.ReadLine());
            string instr = "";
            for (int i = 0; i < side; ++i)
            {
                instr += Console.ReadLine();
            }
            for (int i = 0; i < side; ++i)
            {
                instr += 0;
            }
            char[] poly_char = instr.ToArray();
            int[] polygon = Array.ConvertAll(poly_char, c => (int)Char.GetNumericValue(c));

            bool succeed = true;
            for (int i = 0; i < side*2; ++i)
            {
                for(int j = 0; j < side*side; ++j)
                {
                    if (polygon[j] == 1)
                    {
                        if (polygon[j + side] == 2 || polygon[j + 1] == 2 || j >= side*(side-1) || j%side == side - 1)
                        {
                            polygon[j] = 2;

                        }
                    }
                }
            }
            for (int i = 0; i<side*side; ++i)
            {
                if(polygon[i]== 1)
                {
                    succeed = false;
                    break;
                }
            }
            if (succeed == false)
                Console.WriteLine("NO");
            else
                Console.WriteLine("YES");
        }
    }
}


using System;
using System.Linq;

class Program
{

    static void print2d(char[] arr, int len)
    {
        for (int i = 0; i < len; ++i) {
            for (int j = 0; j < len; ++j) {
                Console.Write(arr[i * len + j]);
            }
            Console.Write('\n');
        }
    }
    static int hori_check(char[] poly, int len)
    {
        int changed = 0;
        int failed = 0;
        for (int i = 0; i < len; ++i) {
            for (int j = 0; j < len; ++j) {
                if (poly[i * len + j] != '1') continue;
                if (j < len - 1 && poly[i * len + j + 1] == '0') {
                    failed = 1;
                }
                else {
                    poly[i * len + j] = '2';
                    changed = 1;
                }
            }
        }
        return failed * 2 + changed;
    }

    static int vert_check(char[] poly, int len)
    {
        int changed = 0;
        int failed = 0;
        for (int j = 0; j < len; ++j) {
            for (int i = 0; i < len; ++i) {
                if (poly[i * len + j] != '1') continue;
                if (i < len - 1 && poly[(i + 1)* len + j] == '0') {
                    failed = 1;
                }
                else {
                    poly[i * len + j] = '2';
                    changed = 1;
                }
            }
        }
        return failed * 2 + changed;
    }

    static void Main(string[] args)
    {
        int n_tc = Convert.ToInt32(Console.ReadLine());
        for (int tc = 0; tc < n_tc; ++tc) {
            int side = Convert.ToInt32(Console.ReadLine());
            string instr = "";
            for (int i = 0; i < side; ++i) {
                instr += Console.ReadLine();
            }
            char[] polygon = instr.ToArray();
            //print2d(polygon, side);

            while (true) {
                int h_res = hori_check(polygon, side);
                int v_res = vert_check(polygon, side);
                if (h_res % 2 == 1 || v_res % 2 == 1) continue;
                if (h_res == 0 && v_res == 0) {
                    Console.WriteLine("Yes");
                }
                else {
                    Console.WriteLine("NO");
                }
                break;
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Polygon
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int t = Next();
            for (int i = 0; i < t; i++)
            {
                writer.WriteLine(Solve() ? "YES" : "NO");
            }
            writer.Flush();
        }

        private static bool Solve()
        {
            int n = Next();

            var nn = new int[n,n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    nn[i, j] = Next(true);
                }
            }

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < n - 1; j++)
                {
                    if (nn[i, j] == 1)
                    {
                        if (nn[i + 1, j] == 0 && nn[i, j + 1] == 0)
                            return false;
                    }
                }
            }

            return true;
        }

        private static int Next(bool one = false)
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            if (one)
                return res;
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = Convert.ToInt32(Console.ReadLine());
            string[] results = new string[t];
            for (int c = 0; c < t; c++)
            {
                int n = Convert.ToInt32(Console.ReadLine());
                int[,] mat = new int[n,n];
                for (int i = 0; i < n; i++)
                {
                    string rowin = Console.ReadLine();
                    int[] line = new int[n];
                    for (int l = 0; l < n; l++)
                    {
                        line[l] = Convert.ToInt32(rowin[l].ToString());
                    }

                    for (int j = 0; j < n; j++)
                    {

                        mat[i,j] = line[j];
                    }
                }
                bool found = false;
                for (int i = 0; i < n-1; i++)
                {
                    for (int j = 0; j < n-1; j++)
                    {
                        if(mat[i,j] == 1 && mat[i+1,j] == 0 && mat[i,j+1] == 0)
                        {
                            found = true;
                        }
                        if(found){break;}
                    }
                    if(found){break;}
                }
                if(found)
                {
                    results[c] = "NO";
                }
                else
                {
                    results[c] = "YES";
                }
            }
            foreach (var item in results)
            {
                Console.WriteLine(item);
            }
        }
    }
}


using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            // int n = Convert.ToInt32(Console.ReadLine());
            // int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
            // StringBuilder stringBuilder = new StringBuilder();
            // for (int t = Convert.ToInt32(Console.ReadLine()); t > 0; t--)
            // {
            // }
            StringBuilder stringBuilder = new StringBuilder();
            for (int t = Convert.ToInt32(Console.ReadLine()); t > 0; t--)
            {
                string[] polygon = new string[Convert.ToInt32(Console.ReadLine())];
                for (int i = 0; i < polygon.Length; i++)
                {
                    polygon[i] = Console.ReadLine();
                }
                bool yes = true;
                for (int i = 0; i < polygon.Length - 1; i++)
                {
                    for (int j = 0; j < polygon.Length - 1; j++)
                    {
                        if (polygon[i][j] == '1')
                        {
                            if (polygon[i + 1][j] != '1' && polygon[i][j + 1] != '1')
                            {
                                yes = false;
                                break;
                            }
                        }
                    }
                }
                if (yes)
                {
                    stringBuilder.AppendLine("YES");
                }
                else
                {
                    stringBuilder.AppendLine("NO");
                }
            }
            Console.Write(stringBuilder);
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            TextReader sr = Console.In;
            //StreamReader sr = new StreamReader("1.txt");
            int t = Convert.ToInt32(sr.ReadLine());
            for (int i = 0; i < t; i++)
            {
                int n = Convert.ToInt32(sr.ReadLine());
                int[,] mm = new int[n, n];
                for (int j = 0; j < n; j++)
                {
                    string sm = sr.ReadLine();
                    for (int k = 0; k < n; k++)
                    {
                        mm[j, k] = Convert.ToInt32(sm[k].ToString());
                    }
                }
                bool res = true;
                for (int j = 0; j < n-1; j++)
                {
                    for (int k = 0; k < n-1; k++)
                    {
                        if (mm[j, k] == 1 && mm[j + 1, k] == 0 && mm[j, k + 1] == 0)
                        {
                            res = false;
                            break;
                        }
                    }
                    if (!res)
                    {
                        break;
                    }
                }
                if (res) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Codeforces2
{
	class Program
	{
		static void Main(string[] args)
		{
			E();
		}

		public static void E()
		{
			var cases = int.Parse(Console.ReadLine());
			var sols = new bool[cases];

			for (int i = 0; i < cases; i++)
			{
				var n = int.Parse(Console.ReadLine());
				var rows = Enumerable.Range(0, n).Select(x => Console.ReadLine().Select(c => c == '1').ToArray()).ToArray();

				bool f = false;

				for (int x = 0; x < n - 1; x++)
				{
					for (int y = 0; y < n - 1; y++)
					{
						if (!rows[x][y])
							continue;

						if (!rows[x + 1][y] && !rows[x][y + 1])
							f = true;
					}
				}

				if (f)
					continue;

				sols[i] = true;
			}

			sols.ToList().ForEach(x => Console.WriteLine(x ? "YES" : "NO"));
		}

		public static List<long> GetPrimes(long maxPrime)
		{
			var list = new List<long> { 2 };
			var array = new bool[maxPrime + 1];
			for (int i = 3; i < array.Length; i += 2)
			{
				if (array[i])
					continue;
				for (int j = 1; i * j < array.Length; j++)
					array[i * j] = true;
				list.Add(i);
			}

			return list;
		}

		private static void D()
		{
			var primes = GetPrimes(100000);
			var cases = int.Parse(Console.ReadLine());
			var sols = new int[cases];

			for (int i = 0; i < cases; i++)
			{
				var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
				var n = ints[0];
				var k = ints[1];
				if (n == k)
				{
					sols[i] = 1;
					continue;
				}

				var divisors = new List<int>();
				var maxDiv = (int)Math.Ceiling(Math.Sqrt(n));
				for (int j = 1; j <= maxDiv; j++)
				{
					if (n % j == 0)
					{
						divisors.Add(j);
						divisors.Add(n / j);
					}
				}

				sols[i] = n / divisors.Where(x => x <= k).Max();
			}

			sols.ToList().ForEach(x => Console.WriteLine(x));

		}

		private static void C()
		{
			var cases = int.Parse(Console.ReadLine());
			var sols = new bool[cases];
			for (int i = 0; i < cases; i++)
			{
				var n = int.Parse(Console.ReadLine());
				var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

				sols[i] = SolveC(ints);
			}

			sols.ToList().ForEach(x => Console.WriteLine(x ? "YES" : "NO"));
		}

		private static bool SolveC(int[] ar)
		{
			var countEven = ar.Count(x => x % 2 == 0);
			if (countEven % 2 == 0)
				return true;

			Array.Sort(ar);
			var subsequent = ar.Zip(ar.Skip(1), (x, y) => Math.Abs(x - y)).Any(c => c == 1);
			return subsequent;
		}

		private static void B()
		{
			var cases = int.Parse(Console.ReadLine());
			for (int i = 0; i < cases; i++)
			{
				var n = int.Parse(Console.ReadLine());
				var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
				Array.Sort(ints);
				var minDiff = ints.Zip(ints.Skip(1), (x, y) => Math.Abs(x - y)).Min();
				Console.WriteLine(minDiff);
			}
		}

		private static void A()
		{
			var cases = int.Parse(Console.ReadLine());
			for (int i = 0; i < cases; i++)
			{
				var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
				var a = ints[0];
				var b = ints[1];
				var min = Math.Min(a, b);
				var max = Math.Max(a, b);
				var sq = Math.Max(max, 2 * min);
				Console.WriteLine(sq * sq);
			}
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        for (int i = 0; i < t; i++)
        {
            int n = sc.NextInt();
            string[] s = new string[n];
            for (int j = 0; j < n; j++)
            {
                s[j] = sc.Next();
            }
            Console.WriteLine(Q(n, s));
        }
        Console.Out.Flush();
    }

    string Q(int n, string[] s)
    {
        bool[,] f = new bool[n + 1, n + 1];
        for (int i = 0; i < n; i++)
        {
            f[n, i] = true;
            f[i, n] = true;
        }
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = n - 1; j >= 0; j--)
            {
                if (s[i][j] == '1')
                {
                    if ((f[i + 1, j] || f[i, j + 1]))
                    {
                        f[i, j] = true;
                    }
                    else
                    {
                        return "NO";
                    }
                }
            }
        }
        return "YES";
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ConsoleReader;

namespace TaskE
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = Read<int>();

            for (var i = 0; i < t; i++)
            {
                Solve();
            }
        }

        private static void Solve()
        {
            var n = Read<int>();
            var poly = new List<string>(n);
            for (var i = 0; i < n; i++)
            {
                var s = Read<string>();
                poly.Add(s);
            }

            for (var i = 0; i < n - 1; i++)
            {
                for (var j = 0; j < n - 1; j++)
                {
                    if (poly[i][j] == '1' && poly[i + 1][j] == '0' && poly[i][j + 1] == '0')
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
            }
            Console.WriteLine("YES");
        }
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }
}


using System;
using System.Numerics;
using System.Text;
using System.IO;
using System.Linq;
using System.Collections.Generic;

class Solution
{
	bool Run()
	{
		int n = Read<int>();
		var A = Enumerable.Range(0, n).Select(i => cin.ReadLine()).ToArray();
		var B = Enumerable.Range(0, n).Select(i => new bool[n]).ToArray();
		var q = new Queue<(int, int)>();
		for (int i = 0; i < n; i++)
		{
			if (A[i][n-1] == '1') {
				q.Enqueue((i, n-1));
			}
			if (A[n-1][i] == '1') {
				q.Enqueue((n-1, i));
			}
		}
		while (q.Count > 0)
		{
			var (i, j) = q.Dequeue();
			if (B[i][j]) continue;
			B[i][j] = true;
			if (i - 1 >= 0 && A[i - 1][j] == '1') q.Enqueue((i - 1, j));
			if (j - 1 >= 0 && A[i][j - 1] == '1') q.Enqueue((i, j - 1));
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (A[i][j] == '1' && !B[i][j]) return false;
			}
		}

		return true;
	}

	// IO Stuff:
	static StreamReader cin = new StreamReader(Console.OpenStandardInput());
	static StreamWriter cout = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
	static void Main()
	{
#if NARUT_LOCAL
	cin = new StreamReader("io/test.in");
#endif
		int n = Read<int>();
		for (int i = 0; i < n; i++) WriteLn((new Solution().Run()) ? "YES" : "NO");
		cout.Flush();
	}
	static T Read<T>()
	{
		return (T)Convert.ChangeType(cin.ReadLine(), typeof(T));
	}
	static T[] ReadMany<T>()
	{
		return Array.ConvertAll(cin.ReadLine().Split(), x => (T)Convert.ChangeType(x, typeof(T)));
	}
	static string Join<T>(T[] arr, string sep = " ")
	{
		return string.Join(sep, Array.ConvertAll(arr, x => x.ToString()));
	}
	static void WriteLn<T>(T t)
	{
		cout.WriteLine(t);
	}
	static void Debug<T>(T t)
	{
#if NARUT_LOCAL
		Console.ForegroundColor = ConsoleColor.Red;
		Console.Error.WriteLine(t);
		Console.ForegroundColor = ConsoleColor.Black;
#endif
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace Pattern.Searching
{
    class MainClass
    {

        static void print<T>(System.Collections.Generic.IEnumerable<T> array)
        {

            Console.WriteLine(string.Join(" ", array));

        }

        static long readInt()
        {

            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {

            var values = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var array = new int[values.Length];
            int c = 0;
            foreach (var item in values)
                array[c] = int.Parse(values[c++]);

            return array;
        }

        static long[] readLongArray()
        {

            var values = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var array = new long[values.Length];
            int c = 0;
            foreach (var item in values)
                array[c] = long.Parse(values[c++]);

            return array;
        }

        static long Solve(long a, long b) {
            if (a <= b)
                return 1;
            if (b == 1)
                return a;

            if (a % 2 == 0)
                return 2;

            long aux = a;
            long i=3;
            for(; i*i<= aux && i<=b; i += 2) {
                if (aux % i == 0)
                    return i;
            }

            return a;
        }

        public static bool solve() {
            var sum = 0;
            var n = readInt();
            int[,] mtz = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                string line = Console.ReadLine();
                for (int j = 0; j < n; j++)
                    mtz[i, j] = line[j] - '0';
            }

            for (int i= (int)n-1; i >= 0; i--)
            for (int j = (int)n-1; j >= 0; j--)
            {
                if (i == n-1 || j == n - 1)
                      continue;

                    if (mtz[i, j] == 1 && mtz[i, j + 1] == 0 && mtz[i + 1, j] == 0)
                        return false;
                }

            return true;
        }

        public static void Main(string[] args)
        {
            var t = readInt();

            while (t-- > 0) {

                Console.WriteLine(solve() ? "YES" : "NO");

            }
        }
    }
}


using System;
class program{
     static void Main(string []args){
          int n=int.Parse(Console.ReadLine());
          for (int i=0;i<n;i++){
               int m=int.Parse(Console.ReadLine());
               int[,]a=new int[m,m];
               for (int j=0;j<m;j++){
                    string tmp=Console.ReadLine();
                    for (int k=0;k<m;k++){
                         a[j,k]=int.Parse(tmp[k].ToString());
                    }
               }
               bool f=false;
               for (int j=0;j<m-1;j++){
                    for (int k=0;k<m-1;k++){
                         if(a[j,k]==1 && (a[j,k+1]!=1 && a[j+1,k]!=1)){
                              f=true;
                         }
                    }
               }
               if(f){
                    Console.WriteLine("NO");
               }
               else{
                    Console.WriteLine("YES");
               }
          }
     }
}


using System;

class _1360E
{
	static string Ans()
	{
		int n = int.Parse(Console.ReadLine());
		string[] a = new string[n];
		for (int i = 0; i < n; ++i)
		{
			a[i] = Console.ReadLine();
		}
		for (int i = 0; i < n - 1; ++i)
		{
			for (int j = 0; j < n - 1; ++j)
			{
				if (a[i][j] == '1' && a[i][j + 1] == '0' && a[i + 1][j] == '0')
				{
					return "NO";
				}
			}
		}
		return "YES";
	}

	static void Main()
	{
		int t = int.Parse(Console.ReadLine());
		string[] anss = new string[t];
		for (int i = 0; i < t; ++i)
		{
			anss[i] = Ans();
		}
		Console.WriteLine(string.Join("\r\n", anss));
	}
}


using System;
using System.Linq;

namespace Codeforces
{
	public class D
	{
		public static int Main()
		{
			int t = Convert.ToInt32(Console.ReadLine());

			while (t-->0)
			{
				int n = Convert.ToInt32(Console.ReadLine());
				char [][] matrix = new char[n][];
				for (int i = 0; i < n; ++i) matrix[i] = Console.ReadLine().ToCharArray();

				for (int i = 0; i < n - 1; ++i)
				{
					for (int j = 0; j < n - 1; ++j)
					{
						if (matrix[i][j] == '0') continue;
						if ((matrix[i][j + 1] == '0') && (matrix[i + 1][j] == '0'))
						{
							Console.WriteLine("NO");
							goto BAD;
						}
					}
				}

				Console.WriteLine("YES");
		BAD:	continue;
			}
			return 0;
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using System.Threading;
using static System.Math;
using static System.Array;
using static AtCoder.IO_ShortCut;
using static AtCoder.Tool;
using static AtCoder.ModInt;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        //const int MOD = 998244353;

        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 };
        static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 };
        //static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>> G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw);

            var th = new Thread(Run, 1 << 26);
            th.Start();
            th.Join();

            //Run();
            Console.Out.Flush();
        }

        static void Run()
        {
            int Testcase = Int;
            for (var _ = 0; _ < Testcase; _++) Solve();
        }
        static void Solve()
        {
            int n = Int;
            var map = new string[n];
            for (var i = 0; i < n; i++) map[i] = Str;
            for(var i = 0; i < n; i++)
            {
                for(var j = 0; j < n; j++)
                {
                    if (map[i][j] == '0') continue;
                    if (i == n - 1 || j == n - 1) continue;
                    if (map[i + 1][j] == '0' && map[i][j + 1] == '0')
                    {
                        OutL("NO");
                        return;
                    }
                }
            }
            OutL("YES");
        }
        public struct Edge
        {
            public int from;

            public int to;
            public long dist;

            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }
        }
    }

    struct ModInt
    {
        public long value;
        private const int MOD = 1000000007;
        //private const int MOD = 998244353;
        public ModInt(long value) { this.value = value; }
        public static implicit operator ModInt(long a)
        {
            var ret = a % MOD;
            return new ModInt(ret < 0 ? (ret + MOD) : ret);
        }
        public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value);
        public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value);
        public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value);
        public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2);
        public static ModInt operator <<(ModInt a, int n) => (a.value << n);
        public static ModInt operator >>(ModInt a, int n) => (a.value >> n);
        public static ModInt operator ++(ModInt a) => a.value + 1;
        public static ModInt operator --(ModInt a) => a.value - 1;
        public static ModInt Modpow(ModInt a, long n)
        {
            var k = a;
            ModInt ret = 1;
            while (n > 0)
            {
                if ((n & 1) != 0) ret *= k;
                k *= k;
                n >>= 1;
            }
            return ret;
        }
        private static readonly List<long> Factorials = new List<long>() { 1 };
        public static ModInt Fac(long n)
        {
            for (var i = Factorials.Count(); i <= n; i++)
            {
                Factorials.Add((Factorials[i - 1] * i) % MOD);
            }
            return Factorials[(int)n];
        }
        public static ModInt nCr(long n, long r)
        {
            return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r));
        }
        public static explicit operator int(ModInt a) => (int)a.value;
    }
    static class IO_ShortCut
    {
        public static string[] _ReadSplit => Console.ReadLine().Split();
        public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse);
        public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse);
        public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse);
        public static string Str => Console.ReadLine();
        public static int Int => int.Parse(Console.ReadLine());
        public static long Long => long.Parse(Console.ReadLine());
        public static double Double => double.Parse(Console.ReadLine());
        public static T Conv<T>(string input)
        {
            if (typeof(T).Equals(typeof(ModInt)))
            {
                return (T)(dynamic)(long.Parse(input));
            }
            return (T)Convert.ChangeType(input, typeof(T));
        }
        public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine());
        public static void Input<T, U>(out T a, out U b)
        { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); }
        public static void Input<T, U, V>(out T a, out U b, out V c)
        { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); }
        public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d)
        { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); }
        public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
        { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); }

        public static void OutL(object s) => Console.WriteLine(s);
        public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s));
        public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s));
        public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s));
        public static void Out_One(object s) => Console.Write($"{s} ");
        public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}");
        public static void Endl() => Console.WriteLine();
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            array = ConvertAll(array, x => initialvalue);
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }
        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }
        static public long Gcd(long a, long b)
        {
            if (a == 0 || b == 0) return Max(a, b);
            return a % b == 0 ? b : Gcd(b, a % b);
        }
        static public long LPow(int a, int b) => (long)Pow(a, b);
        static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
        static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a));
    }
}


/* Date: 25.05.2020 *  Time: 22:45 */
//
// CF 644 E
//
// https://docs.microsoft.com/en-us/dotnet/api/system.tuple-8?redirectedfrom=MSDN&view=netframework-4.7.2
//
//

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;
*/

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Example
{
# if ( ! ONLINE_JUDGE )
	public static StreamReader sr = new StreamReader ("C:\\TRR\\2020\\Task\\07 Codeforces\\047\\E.TXT");
	public static StreamWriter sw = new StreamWriter ("C:\\TRR\\2020\\Task\\07 Codeforces\\047\\OUTPUT.OUT");
# endif

	public const int K = 30003;
	public const int INF = 1800000000;

	public static void Main (string[] args)
	{
		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int q;
# if ( ONLINE_JUDGE )
		q = int.Parse (Console.ReadLine ());
# else
		q = int.Parse (sr.ReadLine ());
		sw.WriteLine ("*** test = " + q);
# endif

		for ( int __q=0; __q < q; __q++ )
		{
			int n;

# if ( ONLINE_JUDGE )
			n = int.Parse (Console.ReadLine ());
//			s = (Console.ReadLine ());
# else
			n = int.Parse (sr.ReadLine ());
//			s = (sr.ReadLine ());
# endif

			string [] s = new string [n];
			for ( int i=0; i < n; i++ )
# if ( ONLINE_JUDGE )
				s [i] = (Console.ReadLine ());
# else
				s [i] = (sr.ReadLine ());
# endif

# if ( ! ONLINE_JUDGE )
			sw.WriteLine ("*** n = " + n);
			for ( int i=0; i < n; i++ )
				sw.WriteLine ("*** < " + s [i] + " >");
# endif

			bool ok = true;
			for ( int i=0; i < n-1; i++ )
			{
				for ( int j=0; j < n-1; j++ )
					if ( s [i][j] == '1' && s [i+1][j] == '0' && s [i][j+1] == '0' )
					{
						ok = false;
						break;
					}
				if ( ! ok )
					break;
			}

# if ( ONLINE_JUDGE )

			if ( ok )
				Console.WriteLine ("YES");
			else
				Console.WriteLine ("NO");

//			Console.WriteLine (m);
# else

			if ( ok )
				sw.WriteLine ("YES");
			else
				sw.WriteLine ("NO");

//			sw.WriteLine (m);
# endif

		}
# if ( ! ONLINE_JUDGE )
		sw.Close ();
# endif
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class DescendingComparer<T> : IComparer<T> where T : IComparable<T>
{
    public int Compare(T x, T y)
    {
        return y.CompareTo(x);
    }
}

public class CF
{

    public static int[] ReadArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m));
    }

    public static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }

    public static string ReadStr()
    {
        return Console.ReadLine();
    }

    public static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }

    public static long[] ReadLongArray()
    {
        return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m));

    }

    public static string IsValid(int n, string[] m)
    {

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {

                if (m[i][j] == '0') continue;

                if (i < n - 1 && m[i + 1][j] == '1') continue;

                if (j < n - 1 && m[i][j + 1] == '1') continue;

                if (i == n - 1 || j == n - 1) continue;

                return "NO";

            }
        }

        return "YES";
    }

    public static void Main()
    {
        int t = ReadInt();

        while (t-- > 0)
        {

            int n = ReadInt();

            string[] s = new string[n];

            for(int i = 1; i <= n; i++)
            {
                s[i - 1] = ReadStr();
            }

            Console.WriteLine(IsValid(n, s));

        }

    }

}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;

namespace AtCoder.Contest.E
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int t = cin.NextInt();
			for (int _i = 0; _i < t; _i++)
			{
				int n = cin.NextInt();
				var s = new List<string>();
                for (int j = 0; j < n; j++)
                {
					s.Add(cin.Next());
                }
				bool ok = true;
                for (int i = 0; i < n - 1; i++)
                {
                    for (int j = 0; j < n - 1; j++)
                    {
						if (s[i][j] == '1' && (s[i][j + 1] == '0' && s[i + 1][j] == '0')) ok = false;
                    }
                }
                if (ok) Console.WriteLine("YES");
                else Console.WriteLine("NO");
			}

			Console.Out.Flush();
		}
	}

	class Printer : StreamWriter
	{
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
		public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


using System;

namespace CodeForces
{
	class Program
	{
		static void Main(string[] args)
		{
			new Polygon();
		}

		class Polygon
		{
			Input[] inputs;

			public Polygon()
			{
				ReadInputs();
				for (int i = 0; i < inputs.Length; i++) Solve(inputs[i]);
			}

			private class Input
			{
				public int size;
				public int[,] data;

				public Input()
				{
					size = Convert.ToInt32(Console.ReadLine());

					data = new int[size, size];

					for (int i = 0; i < size; i++)
					{
						string input = Console.ReadLine();
						for (int j = 0; j < size; j++) data[i, j] = int.Parse(input[j].ToString());
					}
				}
			}

			private void ReadInputs()
			{
				int cases = Convert.ToInt32(Console.ReadLine());
				inputs = new Input[cases];

				for (int i = 0; i < cases; i++) inputs[i] = new Input();
			}

			private void Solve(Input tInput)
			{
				for (int i = 0; i < tInput.size; i++)
					for (int j = 0; j < tInput.size; j++)
						if (tInput.data[i, j] == 1 && !PossibleCondition(tInput, i, j))
						{
							Console.WriteLine("NO");
							return;
						}

				Console.WriteLine("YES");
			}

			private bool PossibleCondition(Input tInput, int i, int j)
			{
				int size = tInput.size;
				return i == size - 1 || j == size - 1 || (i < size - 1 && tInput.data[i + 1, j] == 1) || (j < size - 1 && tInput.data[i, j + 1] == 1);
			}
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Olympo
{

    class Program
    {

        static void Main(string[] args)
        {
            var t = int.Parse(Console.ReadLine());
            for(int tc = 1; tc <= t; tc++)
            {
                var n = int.Parse(Console.ReadLine());
                var mas = new string[n];
                for (int i = 0; i < n; i++)
                    mas[i] = Console.ReadLine();
                var res = true;
                for(int i=0;i < n-1; i++)
                    for (int j = 0; j < n - 1; j++)
                    {
                        if( mas[i][j] == '1' && mas[i+1][j] == '0' && mas[i][j+1] == '0')
                        {
                            res = false;
                            break;
                        }
                    }
                Console.WriteLine(res ? "YES" : "NO");
            }

        }

    }
}