#include <stdio.h>
#include <string.h>
#define forfor(func) for(int i=0;i<n;i++)\
for(int j=0;j<n;j++) {\
(func); }
int main()
{
int n,m,p;
scanf("%d %d",&n,&m);
int arr[n][n],arr2[n][n];
forfor( scanf("%d",&arr[i][j]))
while (m--)
{
scanf("%d",&p);
if (p==1) forfor(arr2[j][n-i-1]=arr[i][j])
if (p==2) forfor(arr2[n-j-1][i]=arr[i][j])
if (p==3) forfor(arr2[n-i-1][n-j-1]=arr[i][j])
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",arr2[i][j]);
arr[i][j]=arr2[i][j];
}
printf("\n");}
printf("\n");
}
return 0;
}