#include <bits/stdc++.h>
using namespace std;
int n, m, r, c, si, an;
bool a[20][20], b[20][20];
void check() {
  cout << endl;
  cout << " --------------------------" << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j];
      if (j != n - 1) cout << " ";
    }
    cout << endl;
  }
  cout << "--------------------------" << endl;
  cout << endl;
}
void rotate() {
  for (int rt = 0; rt < an / 90; rt++) {
    for (int i = 0; i < si; i++) {
      for (int j = 0; j < si; j++) {
        b[r + i][c + j] = a[c + si - j - 1][r + i];
      }
    }
    for (int i = 0; i < si; i++)
      for (int j = 0; j < si; j++) a[r + i][c + j] = b[r + i][c + j];
  }
}
void reversal() {
  for (int i = r; i < r + si; i++) {
    for (int j = c; j < c + si; j++) {
      a[i][j] = !a[i][j];
    }
  }
}
void IR(int x, int y) {
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {-1, 1, 0, 0};
  a[y][x] = !a[y][x];
  for (int i = 0; i < 4; i++) {
    if (y + dy[i] >= 0 && y + dy[i] < n && x + dx[i] >= 0 && x + dx[i] < n)
      if (a[y + dy[i]][x + dx[i]] != a[y][x]) IR(x + dx[i], y + dy[i]);
  }
}
void RS() {
  a[r][0] = b[r][n - 1];
  for (int i = 1; i < n; i++) a[r][i] = b[r][i - 1];
  for (int i = 0; i < n; i++) b[r][i] = a[r][i];
}
void LS() {
  a[r][n - 1] = b[r][0];
  for (int i = n - 2; i >= 0; i--) a[r][i] = b[r][i + 1];
  for (int i = 0; i < n; i++) b[r][i] = a[r][i];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      b[i][j] = a[i][j];
    }
  }
  int o;
  for (int i = 0; i < m; i++) {
    cin >> o;
    if (o == 0) {
      cin >> r >> c >> si >> an;
      r--;
      c--;
      rotate();
    } else if (o == 1) {
      cin >> r >> c >> si;
      r--;
      c--;
      reversal();
    } else if (o == 2) {
      cin >> r;
      r--;
      LS();
    } else if (o == 3) {
      cin >> r;
      r--;
      RS();
    } else if (o == 4) {
      cin >> r >> c;
      r--;
      c--;
      IR(c, r);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j];
      if (j != n - 1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}
