#include<bits/stdc++.h>
using namespace std;
main(){
int n,m;
cin>>n>>m;
int a[n][n];
int x=n*n;
int work[x];
int lin=0;
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
cin>>a[i][j];
}
}
int t;
while(m--){
cin>>t;
if(t==1){
for(int j=0;j<n;++j){
for(int i=n-1;i>=0;--i){
int k=a[i][j];
work[lin]=k;
++lin;
}
}
for(int i=0;i<x;++i){
cout<<work[i]<<" ";
if((i+1)%n==0)cout<<endl;
}
cout<<endl;
}
if(t==2){
for(int j=n-1;j>=0;--j){
for(int i=0;i<n;++i){
int k=a[i][j];
work[lin]=k;
++lin;
}
}
for(int i=0;i<x;++i){
cout<<work[i]<<" ";
if((i+1)%n==0)cout<<endl;
}
cout<<endl;
}
if(t==3){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j){
work[lin]=a[i][j];
++lin;
}
}
for(int i=x-1;i>=0;--i){
cout<<work[i]<<" ";
if(i%n==0)cout<<endl;
}
cout<<endl;
}
}
}
谢谢