#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct node {     long long k[51][51];   } a, ans;   long long t, n, m, q, op, x, y, z, s = 1, mp[26][26];   inline long long read() {     long long sum = 0, x = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) x = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       sum = sum * 10 + ch -  0 ;       ch = getchar();     }     return sum * x;   }   inline void write(long long x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );     return;   }   inline node mul(node a, node b) {     node c;     memset(c.k, 0, sizeof(c.k));     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j)         for (register long long p = 1; p <= t; p++)           c.k[i][j] = (c.k[i][j] + a.k[i][p] * b.k[p][j]) % mod;     return c;   }   inline void power(long long b) {     for (; b; b >>= 1, a = mul(a, a))       if (b & 1) ans = mul(a, ans);   }   inline void build() {     for (register long long i = 1; i <= t; ++i)       for (register long long j = 1; j <= t; ++j) {         long long aa = ((i - 1) / m) + 1, bb = (i - 1) % m + 1,                   A = ((j - 1) / m) + 1, B = (j - 1) % m + 1;         if (mp[aa][bb] == 0 && mp[A][B] == 0 && abs(A - aa) + abs(B - bb) <= 1)           a.k[i][j] = 1;         else           a.k[i][j] = 0;       }   }   signed main() {     n = read();     m = read();     q = read();     t = n * m;     ans.k[1][1] = 1;     while (q--) {       build();       op = read();       x = read();       y = read();       z = read();       power(z - s);       s = z;       if (op == 2 || op == 3) ans.k[(x - 1) * m + y][1] = 0;       if (op == 2) mp[x][y] = 1;       if (op == 3) mp[x][y] = 0;       if (op == 1) {         write(ans.k[(x - 1) * m + y][1]);         putchar(  n );       }     }     return 0;   }   