#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < (int)(N); ++i)
    for (int j = 0; j < (int)(N); ++j) cin >> a[i][j];
  for (int i = 0; i < (int)(M); ++i) {
    int ope;
    cin >> ope;
    if (ope == 0) {
      int y, x, l, arg;
      cin >> y >> x >> l >> arg;
      x--;
      y--;
      arg /= 90;
      while (arg--) {
        int tmp[100][100];
        for (int i = 0; i < (int)(N); ++i)
          for (int j = 0; j < (int)(N); ++j) tmp[i][j] = a[i][j];
        for (int dy = 0; dy < (int)(l); ++dy)
          for (int dx = 0; dx < (int)(l); ++dx) {
            a[y + dy][x + dx] = tmp[x + l - 1 - dx][y + dy];
          }
      }
    } else if (ope == 1) {
      int y, x, l;
      cin >> y >> x >> l;
      x--;
      y--;
      for (int dy = 0; dy < (int)(l); ++dy)
        for (int dx = 0; dx < (int)(l); ++dx) a[y + dy][x + dx] ^= 1;
    } else if (ope == 2) {
      int y;
      cin >> y;
      y--;
      int tmp[100];
      for (int x = 0; x < (int)(N); ++x) tmp[x] = a[y][x];
      for (int x = 0; x < (int)(N); ++x) a[y][x] = tmp[(x + 1) % N];
    } else if (ope == 3) {
      int y;
      cin >> y;
      y--;
      int tmp[100];
      for (int x = 0; x < (int)(N); ++x) tmp[x] = a[y][x];
      for (int x = 0; x < (int)(N); ++x) a[y][x] = tmp[(x + N - 1) % N];
    } else if (ope == 4) {
      int y, x;
      cin >> y >> x;
      x--;
      y--;
      bool b[100][100] = {};
      b[y][x] = true;
      int dx[4] = {1, 0, -1, 0};
      int dy[4] = {0, 1, 0, -1};
      bool update = true;
      while (update) {
        update = false;
        for (int i = 0; i < (int)(N); ++i)
          for (int j = 0; j < (int)(N); ++j)
            if (b[i][j])
              for (int r = 0; r < (int)(4); ++r)
                if (0 <= i + dy[r] && i + dy[r] < N && 0 <= j + dx[r] &&
                    j + dx[r] < N && a[i][j] == a[i + dy[r]][j + dx[r]]) {
                  if (!b[i + dy[r]][j + dx[r]]) update = true;
                  b[i + dy[r]][j + dx[r]] = true;
                }
      }
      for (int i = 0; i < (int)(N); ++i)
        for (int j = 0; j < (int)(N); ++j)
          if (b[i][j]) a[i][j] ^= 1;
    }
  }
  for (int y = 0; y < (int)(N); ++y) {
    for (int x = 0; x < (int)(N); ++x) {
      cout << a[y][x];
      if (x == N - 1)
        cout << endl;
      else
        cout << " ";
    }
  }
  return 0;
}
