#include <bits/stdc++.h>
using namespace std;
int n;
void f(int data[20][20], int size) {
  int tmp[20][20];
  for (long long i = 0; i < (long long)(20); i++)
    for (long long j = 0; j < (long long)(20); j++) tmp[i][j] = data[i][j];
  for (long long i = 0; i < (long long)(size); i++) {
    for (long long j = 0; j < (long long)(size); j++) {
      data[i][j] = tmp[size - j - 1][i];
    }
  }
}
void output(int data[20][20], int l) {
  for (long long i = 0; i < (long long)(l); i++) {
    for (long long j = 0; j < (long long)(l); j++) {
      cout << data[i][j] << " ";
    }
    cout << endl;
  }
}
void turn(int data[20][20], int r, int c, int size, int angle) {
  int tmp[20][20];
  for (int y = 0, i = r; i <= r + size - 1; i++, y++) {
    for (int x = 0, j = c; j <= c + size - 1; j++, x++) {
      tmp[y][x] = data[i][j];
    }
  }
  angle /= 90;
  for (long long i = 0; i < (long long)(angle); i++) f(tmp, size);
  for (int y = 0, i = r; i <= r + size - 1; i++, y++) {
    for (int x = 0, j = c; j <= c + size - 1; j++, x++) {
      data[i][j] = tmp[y][x];
    }
  }
}
vector<pair<int, int> > p;
void dfs(int data[20][20], int y, int x, bool used[20][20]) {
  p.push_back(pair<int, int>(y, x));
  used[y][x] = true;
  int dy[] = {1, 0, -1, 0};
  int dx[] = {0, 1, 0, -1};
  for (long long i = 0; i < (long long)(4); i++) {
    int ddy = y + dy[i];
    int ddx = x + dx[i];
    if (ddx >= 0 && ddy >= 0 && ddx < n && ddy < n && !used[ddy][ddx] &&
        data[y][x] == data[ddy][ddx]) {
      dfs(data, ddy, ddx, used);
    }
  }
}
int main() {
  int m;
  cin >> n >> m;
  int data[20][20];
  for (long long i = 0; i < (long long)(n); i++)
    for (long long j = 0; j < (long long)(n); j++) cin >> data[i][j];
  for (long long i = 0; i < (long long)(m); i++) {
    int o;
    cin >> o;
    if (o == 0) {
      int r, c, size, angle;
      cin >> r >> c >> size >> angle;
      r--, c--;
      turn(data, r, c, size, angle);
    } else if (o == 1) {
      int r, c, size;
      cin >> r >> c >> size;
      r--, c--;
      for (int i = r; i <= r + size - 1; i++) {
        for (int j = c; j <= c + size - 1; j++) {
          data[i][j] = !data[i][j];
        }
      }
    } else if (o == 2) {
      int r;
      cin >> r;
      r--;
      data[r][n] = data[r][0];
      for (long long i = 0; i < (long long)(n); i++)
        data[r][i] = data[r][i + 1];
      data[r][n] = 0;
    } else if (o == 3) {
      int r;
      cin >> r;
      r--;
      for (long long i = 0; i < (long long)(n); i++)
        data[r][i + 1] = data[r][i];
      data[r][0] = data[r][n];
      data[r][n] = 0;
    } else if (o == 4) {
      int r, c;
      cin >> r >> c;
      r--, c--;
      p.clear();
      bool used[20][20] = {};
      dfs(data, r, c, used);
      for (long long i = 0; i < (long long)(p.size()); i++) {
        int y = p[i].first, x = p[i].second;
        data[y][x] = !data[y][x];
      }
    }
  }
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(n); j++) {
      if (j != 0) cout << " ";
      cout << data[i][j];
    }
    cout << endl;
  }
}
