#include <bits/stdc++.h>
using namespace std;
int M[44][44], Me[44][44], V[44], Ve[44], C[44][44];
int x, y, n;
void build() {
  int a, b, A, B, i, j, k;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      a = i / y;
      b = i % y;
      A = j / y;
      B = j % y;
      k = abs(A - a) + abs(B - b);
      if (k <= 1 && C[a][b] == 0 && C[A][B] == 0)
        M[i][j] = 1;
      else
        M[i][j] = 0;
    }
}
int main() {
  int i, j, k, l, q, a, b, t = 1, e, mod = 1000000007;
  V[0] = 1;
  scanf("%d%d%d", &x, &y, &q);
  n = x * y;
  while (q--) {
    build();
    scanf("%d%d%d%d", &l, &a, &b, &k);
    --a;
    --b;
    e = k - t;
    t = k;
    while (1) {
      if (e & 1) {
        for (i = 0; i < n; i++)
          for (Ve[i] = j = 0; j < n; j++)
            Ve[i] = (Ve[i] + M[i][j] * (long long)V[j]) % mod;
        for (i = 0; i < n; i++) V[i] = Ve[i];
      }
      e >>= 1;
      if (e == 0) break;
      for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
          for (Me[i][j] = k = 0; k < n; k++)
            Me[i][j] = (Me[i][j] + M[i][k] * (long long)M[k][j]) % mod;
      for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) M[i][j] = Me[i][j];
    }
    if (l == 3) {
      V[a * y + b] = 0;
      C[a][b] = 0;
    }
    if (l == 2) {
      V[a * y + b] = 0;
      C[a][b] = 1;
    }
    if (l == 1) printf("%d\n", V[a * y + b]);
  }
  return 0;
}
