Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- int main()
- {
- fast()
- int t;
- cin>>t;
- while(t--)
- {
- int n,i,j,cnt=0,mx=1;
- cin>>n;
- for(i=1;i<=n;i++)
- {
- bool f;
- if(i%2==1)
- {
- //cout<<++cnt<<" ";
- cnt=mx;
- mx+=n;
- f=true;
- }
- else
- {
- cnt=mx+n;
- mx+=n;
- f=false;
- }
- for(j=1;j<=n;j++)
- {
- if(f)
- {
- cout<<cnt++<<" ";
- }
- else cout<<--cnt<<" ";
- }
- cout<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement