#include <bits/stdc++.h>
const int N = 30;
const long long MOD = 1e9 + 7;
using namespace std;
int n, R, C, Q, cnt = 0, lt = 1, vis[N][N];
long long f[30], g[N];
int ex[5] = {0, 0, 0, 1, -1}, ey[5] = {0, 1, -1, 0, 0};
struct nn {
  long long a[30][30];
  void PRT() {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf("%lld ", a[i][j]);
      printf("\n");
    }
    printf("\n");
  }
};
nn T, las;
nn INIT() {
  nn res;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) res.a[i][j] = 0;
  for (int i = 1; i <= R; i++) {
    for (int j = 1; j <= C; j++) {
      if (vis[i][j]) continue;
      int now = (i - 1) * C + j;
      for (int k = 0; k <= 4; k++) {
        int nx = i + ex[k], ny = j + ey[k];
        if (nx < 1 || ny < 1 || nx > R || ny > C) continue;
        if (vis[nx][ny]) continue;
        int pos = (nx - 1) * C + ny;
        res.a[now][pos] = 1;
      }
    }
  }
  return res;
}
nn MUL(nn A, nn B) {
  nn res;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) res.a[i][j] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 1; k <= n; k++) {
        res.a[i][j] += A.a[i][k] * B.a[k][j] % MOD;
        res.a[i][j] %= MOD;
      }
    }
  }
  return res;
}
nn KSM(nn A, int y) {
  nn res;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) res.a[i][j] = 0;
    res.a[i][i] = 1;
  }
  while (y) {
    if (y % 2 == 1) res = MUL(res, A);
    A = MUL(A, A);
    y /= 2;
  }
  return res;
}
void MMUL(nn A) {
  for (int i = 1; i <= n; i++) g[i] = 0;
  for (int i = 1; i <= n; i++) {
    if (i % C == 0 && vis[i / C][C]) continue;
    if (i % C != 0 && vis[i / C + 1][i % C]) continue;
    for (int j = 1; j <= n; j++) {
      g[i] += f[j] * A.a[j][i] % MOD;
      g[i] %= MOD;
    }
  }
  for (int i = 1; i <= n; i++) f[i] = g[i];
}
void SOLVE() {
  int pd, x, y, t;
  scanf("%d%d%d%d", &pd, &x, &y, &t);
  int dt = t - lt;
  lt = t;
  MMUL(KSM(las, dt));
  if (pd == 2) {
    vis[x][y]++;
    cnt++;
    f[(x - 1) * C + y] = 0;
    las = INIT();
  }
  if (pd == 3) {
    vis[x][y]--;
    cnt--;
    if (cnt == 0)
      las = T;
    else
      las = INIT();
  }
  if (pd == 1) printf("%lld\n", f[(x - 1) * C + y]);
}
int main() {
  scanf("%d%d%d", &R, &C, &Q);
  n = R * C;
  T = INIT();
  f[1] = 1;
  lt = 1;
  las = T;
  while (Q--) SOLVE();
  return 0;
}
