#include <bits/stdc++.h>
#include <cstdio>
#define int long long
using namespace std;
const int N = 1e3 + 5;
int n,m;
int a [N] [N],b [N] [N];
void solve ()
{
bool op;
int x,y;
cin >> op >> x >> y;
if (x == y) return ;
if (! op)
for (int i = 1;i <= n;i ++) a [i] [x] = b [i] [y],a [i] [y] = b [i] [x];
else
for (int i = 1;i <= n;i ++) a [x] [i] = b [y] [i],a [y] [i] = b [x] [i];
for (int i = 1;i <= n;i ++)
for (int j = 1;j <= n;j ++) b [i] [j] = a [i] [j];
}
signed main ()
{
ios :: sync_with_stdio (false);
cin.tie (0),cout.tie (0);
cin >> n >> m;
for (int i = 1;i <= n;i ++)
for (int j = 1;j <= n;j ++) cin >> a [i] [j],b [i] [j] = a [i] [j];
while (m --) solve ();
for (int i = 1;i <= n;i ++)
{
for (int j = 1;j <= n;j ++) cout << a [i] [j] << ' ';
cout << endl;
}
return 0;
}