#include <bits/stdc++.h>
using namespace std;
int n, m;
int t[15][15];
vector<int> v[15];
void vrotate(int r, int c, int size, int angle) {
  if (angle == 0 || angle == 360) return;
  memset(t, 0, sizeof(t));
  for (int i = 0; i < angle / 90; i++) {
    int col = c;
    for (int i = r + size - 1; i >= r; i--, col++) {
      for (int j = c; j < c + size; j++) {
        t[r + j - c][col] = v[i][j];
      }
    }
    for (int i = r; i < r + size; i++) {
      for (int j = c; j < c + size; j++) {
        v[i][j] = t[i][j];
      }
    }
  }
}
void reversal(int r, int c, int size) {
  for (int i = r; i < r + size; i++) {
    for (int j = c; j < c + size; j++) {
      v[i][j] = !v[i][j];
    }
  }
}
void leftshift(int r) { rotate(v[r].begin(), v[r].begin() + 1, v[r].end()); }
void rightshift(int r) {
  rotate(v[r].rbegin(), v[r].rbegin() + 1, v[r].rend());
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool can(int y, int x) {
  if (0 <= y && y < n && 0 <= x && x < n) return true;
  return false;
}
void islandreversal(int r, int c) {
  queue<pair<int, int> > que;
  que.push(make_pair(r, c));
  int t = v[r][c];
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int y = p.first, x = p.second;
    if (v[y][x] == t) {
      v[y][x] = !v[y][x];
    }
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (can(ny, nx) && v[ny][nx] == t) {
        que.push(make_pair(ny, nx));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  memset(v, 0, sizeof(v));
  for (int i = 0; i < n; i++) {
    v[i].resize(n);
    for (int j = 0; j < n; j++) cin >> v[i][j];
  }
  for (int i = 0; i < m; i++) {
    int o;
    cin >> o;
    int r, c, size, angle;
    if (o == 0) {
      cin >> r >> c >> size >> angle;
      r--;
      c--;
      vrotate(r, c, size, angle);
    } else if (o == 1) {
      cin >> r >> c >> size;
      r--;
      c--;
      reversal(r, c, size);
    } else if (o == 2) {
      cin >> r;
      r--;
      leftshift(r);
    } else if (o == 3) {
      cin >> r;
      r--;
      rightshift(r);
    } else if (o == 4) {
      cin >> r >> c;
      r--;
      c--;
      islandreversal(r, c);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << v[i][j];
      if (j == n - 1)
        cout << endl;
      else
        cout << " ";
    }
  }
  return 0;
}
