#include <bits/stdc++.h>
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
int n, m;
array<array<int, 20>, 20> mat;
void rotate(int r1, int c1, int size) {
  array<array<int, 20>, 20> tmp(mat);
  for (int r = r1; r < r1 + size; r++) {
    for (int c = c1; c < c1 + size; c++) {
      tmp[c][c1 + n - r - 1] = mat[r][c];
    }
  }
  mat = tmp;
}
void reversal(int r1, int c1, int size) {
  for (int r = r1; r < r1 + size; r++) {
    for (int c = c1; c < c1 + size; c++) mat[r][c] ^= 1;
  }
}
void left_shift(int r1) {
  int tmp = mat[r1][0];
  for (int c = 0; c < (n - 1); c++) mat[r1][c] = mat[r1][c + 1];
  mat[r1][n - 1] = tmp;
}
void right_shift(int r1) {
  int tmp = mat[r1][n - 1];
  for (int c = n - 1; c >= 1; c--) mat[r1][c] = mat[r1][c - 1];
  mat[r1][0] = tmp;
}
void island_reversal(int r1, int c1) {
  int val = mat[r1][c1];
  mat[r1][c1] ^= 1;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(r1, c1));
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int r = p.first;
    int c = p.second;
    for (int i = 0; i < (4); i++) {
      int nr = r + dy[i];
      int nc = c + dx[i];
      if (nr < 0 || nc < 0) continue;
      if (nr >= n || nc >= n) continue;
      if (mat[nr][nc] != val) continue;
      mat[nr][nc] ^= 1;
      que.push(pair<int, int>(nr, nc));
    }
  }
}
void dump() {
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (n); j++) {
      cout << mat[i][j];
      if (j + 1 == n)
        cout << endl;
      else
        cout << " ";
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) cin >> mat[i][j];
  for (int i = 0; i < (m); i++) {
    int op;
    cin >> op;
    if (op == 0) {
      int r, c, size, ang;
      cin >> r >> c >> size >> ang;
      r--, c--;
      for (int i = 0; i < (ang / 90); i++) rotate(r, c, size);
    }
    if (op == 1) {
      int r, c, size;
      cin >> r >> c >> size;
      r--, c--;
      reversal(r, c, size);
    }
    if (op == 2) {
      int r;
      cin >> r;
      r--;
      left_shift(r);
    }
    if (op == 3) {
      int r;
      cin >> r;
      r--;
      right_shift(r);
    }
    if (op == 4) {
      int r, c, size;
      cin >> r >> c;
      r--, c--;
      island_reversal(r, c);
    }
  }
  dump();
  return 0;
}
