func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, tot;   bool ok(int i, int j) {     if (i < 0 or i >= n or j < 0 or j >= m) return 0;     return 1;   }   long long int c[20][20] = {0};   void matcpy(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         a[i][j] = b[i][j];       }     }   }   void mul(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         c[i][j] = 0;         for (int k = 0; k < tot; k++) {           c[i][j] += (a[i][k] * b[k][j]) % 1000000007;           c[i][j] %= 1000000007;         }       }     }     matcpy(a, c);   }   long long int id[20][20] = {0};   int cat[20][20] = {0};   void bpow(long long int a[20][20], int k) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           id[i][j] = 1;         else           id[i][j] = 0;       }     }     while (k > 0) {       if (k & 1) mul(id, a);       mul(a, a);       k /= 2;     }     matcpy(a, id);   }   long long int mat[20][20] = {0};   long long int T[20][20] = {0};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q, x, y, t, tp;     cin >> n >> m >> q;     tot = n * m;     int prev = 1;     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           mat[i][j] = 1;         else           mat[i][j] = 0;       }     }     while (q--) {       cin >> tp >> x >> y >> t;       x--;       y--;       for (int i1 = 0; i1 < n; i1++) {         for (int j1 = 0; j1 < m; j1++) {           for (int i2 = 0; i2 < n; i2++) {             for (int j2 = 0; j2 < m; j2++) {               if (!cat[i1][j1] and !cat[i2][j2] and                   abs(i1 - i2) + abs(j1 - j2) <= 1) {                 T[m * i1 + j1][m * i2 + j2] = 1;               } else {                 T[m * i1 + j1][m * i2 + j2] = 0;               }             }           }         }       }       bpow(T, t - prev);       prev = t;       mul(mat, T);       if (tp == 1) {         cout << mat[0][m * x + y] <<   n ;       } else if (tp == 2) {         cat[x][y] = 1;       } else {         cat[x][y] = 0;       }     }   }   