#include <bits/stdc++.h>
using namespace std;
int n, m, k, i, j, tp, x, y, t, dp[20], d[20][20], e[20][20],
    yon[5][2] = {{0, 0}, {1, 0}, {0, 1}, {-1, 0}, {0, -1}}, q, last, res,
    dp2[20], t1;
bool gez[20][20];
void build() {
  memset(d, 0, sizeof d);
  int i, j, l, x1, y1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      for (l = 0; l < 5; l++) {
        x1 = i + yon[l][0];
        y1 = j + yon[l][1];
        if (x1 >= 0 and x1 < n and y1 >= 0 and y1 < m and !gez[i][j] and
            !gez[x1][y1])
          d[m * i + j][m * x1 + y1] = 1;
      }
    }
  }
  memcpy(e, d, sizeof d);
}
void crp() {
  int i, j, l, tmp[20][20], res;
  for (i = 0; i < k; i++) {
    for (j = 0; j < k; j++) {
      res = 0;
      for (l = 0; l < k; l++)
        res = (res + 1ll * d[i][l] * e[l][j]) % 1000000007;
      tmp[i][j] = res;
    }
  }
  memcpy(d, tmp, sizeof tmp);
}
void mrg() {
  int i, j, l, tmp[20][20], res;
  for (i = 0; i < k; i++) {
    for (j = 0; j < k; j++) {
      res = 0;
      for (l = 0; l < k; l++)
        res = (res + 1ll * d[i][l] * d[l][j]) % 1000000007;
      tmp[i][j] = res;
    }
  }
  memcpy(d, tmp, sizeof tmp);
}
void carp(int x) {
  if (x == 1) return;
  carp(x / 2);
  mrg();
  if (x % 2) crp();
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  k = n * m;
  last = 1;
  dp[0] = 1;
  for (t1 = 0; t1 < q; t1++) {
    scanf("%d %d %d %d", &tp, &x, &y, &t);
    x--;
    y--;
    build();
    carp(t - last);
    last = t;
    for (i = 0; i < k; i++) {
      res = 0;
      for (j = 0; j < k; j++) res = (res + 1ll * dp[j] * d[j][i]) % 1000000007;
      dp2[i] = res;
    }
    for (i = 0; i < k; i++) dp[i] = dp2[i];
    if (tp == 1)
      printf("%d\n", dp[x * m + y]);
    else if (tp == 2) {
      gez[x][y] = 1;
      dp[x * m + y] = 0;
    } else
      gez[x][y] = 0;
  }
  return 0;
}
