#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(n));
  for (int(i) = 0; (i) < (int)(n); ++(i))
    for (int(j) = 0; (j) < (int)(n); ++(j)) cin >> a[i][j];
  for (int(M) = 0; (M) < (int)(m); ++(M)) {
    int op;
    scanf(" %d", &op);
    vector<vector<int> > b(a);
    if (op == 0) {
      int r, c, size, angle;
      scanf(" %d %d %d %d", &r, &c, &size, &angle);
      --r;
      --c;
      for (int(T) = 0; (T) < (int)(angle / 90); ++(T)) {
        vector<vector<int> > t(b);
        for (int i = r; i < r + size; ++i)
          for (int j = c; j < c + size; ++j)
            t[r + (j - c)][r + size - 1 - (i - r)] = b[i][j];
        for (int i = r; i < r + size; ++i)
          for (int j = c; j < c + size; ++j) b[i][j] = t[i][j];
      }
    } else if (op == 1) {
      int r, c, size;
      scanf(" %d %d %d", &r, &c, &size);
      --r;
      --c;
      for (int i = r; i < r + size; ++i)
        for (int j = c; j < c + size; ++j) b[i][j] = !b[i][j];
    } else if (op == 2) {
      int r;
      scanf(" %d", &r);
      --r;
      int tmp = b[r][0];
      for (int(i) = 0; (i) < (int)(n - 1); ++(i)) b[r][i] = b[r][i + 1];
      b[r][n - 1] = tmp;
    } else if (op == 3) {
      int r;
      scanf(" %d", &r);
      --r;
      int tmp = b[r][n - 1];
      for (int i = n - 1; i > 0; --i) b[r][i] = b[r][i - 1];
      b[r][0] = tmp;
    } else {
      int r, c;
      scanf(" %d %d", &r, &c);
      --r;
      --c;
      int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1};
      vector<vector<int> > vis(n, vector<int>(n, 0));
      vis[r][c] = 1;
      queue<pair<int, int> > que;
      que.push(pair<int, int>(r, c));
      while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        for (int(i) = 0; (i) < (int)(4); ++(i)) {
          int nr = v.first + dr[i], nc = v.second + dc[i];
          if (0 <= nr && nr < n && 0 <= nc && nc < n) {
            if (!vis[nr][nc] && b[nr][nc] == b[r][c]) {
              vis[nr][nc] = 1;
              que.push(pair<int, int>(nr, nc));
            }
          }
        }
      }
      for (int(i) = 0; (i) < (int)(n); ++(i))
        for (int(j) = 0; (j) < (int)(n); ++(j)) {
          if (vis[i][j]) b[i][j] = !b[i][j];
        }
    }
    a = b;
  }
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    for (int(j) = 0; (j) < (int)(n); ++(j)) {
      if (j) printf(" ");
      printf("%d", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}
