#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
const int L = 20 + 3;
const long long MOD = 1e9 + 7;
const long long MM = 8e18;
int f[L][L];
int n, m, q;
struct Matrix {
  int l;
  long long f[L][L];
  Matrix() { memset(f, 0, sizeof(f)), l = 0; }
} f1, f2;
struct Query {
  int tp, x, y, t;
} g[N];
long long ans[N];
int l[5] = {0, 1, -1, 0, 0};
int r[5] = {0, 0, 0, 1, -1};
Matrix Mul(Matrix x, Matrix y) {
  Matrix z;
  z.l = x.l;
  for (int i = 1; i <= z.l; i++)
    for (int j = 1; j <= z.l; j++) {
      z.f[i][j] = 0;
      for (int k = 1; k <= z.l; k++) {
        z.f[i][j] += x.f[i][k] * y.f[k][j];
        if (z.f[i][j] >= MM) z.f[i][j] %= MOD;
      }
      if (z.f[i][j] >= MOD) z.f[i][j] %= MOD;
    }
  return z;
}
Matrix initial(int l) {
  Matrix x;
  x.l = l;
  for (int i = 1; i <= l; i++)
    for (int j = 1; j <= l; j++) x.f[i][j] = (i == j ? 1 : 0);
  return x;
}
Matrix ksm(Matrix a, int b) {
  Matrix x = initial(n * m);
  while (b > 0) {
    if (b & 1) x = Mul(x, a);
    b >>= 1;
    a = Mul(a, a);
  }
  return x;
}
bool outside(int x, int y) {
  if (x <= 0 || y <= 0 || x > n || y > m) return true;
  return false;
}
void add(int x, int y) {
  int nx, ny;
  f2.f[f[x][y]][f[x][y]] = 1;
  for (int i = 1; i <= 4; i++) {
    nx = x + l[i], ny = y + r[i];
    if (outside(nx, ny)) continue;
    f2.f[f[nx][ny]][f[x][y]] = 1;
  }
}
void del(int x, int y) {
  int nx, ny;
  f2.f[f[x][y]][f[x][y]] = 0;
  for (int i = 1; i <= 4; i++) {
    nx = x + l[i], ny = y + r[i];
    if (outside(nx, ny)) continue;
    f2.f[f[nx][ny]][f[x][y]] = 0;
  }
}
void init() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) f[i][j] = (i - 1) * m + j;
  for (int i = 1; i <= q; i++)
    scanf("%d%d%d%d", &g[i].tp, &g[i].x, &g[i].y, &g[i].t);
  f1.l = f2.l = n * m;
  f1.f[1][1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) add(i, j);
}
void work() {
  int now;
  g[0].t = 1;
  for (int i = 1; i <= q; i++) {
    f1 = Mul(f1, ksm(f2, g[i].t - g[i - 1].t));
    now = f[g[i].x][g[i].y];
    switch (g[i].tp) {
      case 1:
        ans[i] = f1.f[1][now];
        ans[i] %= MOD;
        break;
      case 2:
        del(g[i].x, g[i].y);
        f1.f[1][now] = 0;
        break;
      case 3:
        add(g[i].x, g[i].y);
        break;
      default:
        break;
    }
  }
  for (int i = 1; i <= q; i++)
    if (g[i].tp == 1) printf("%I64d\n", ans[i]);
}
int main() {
  init();
  work();
  return 0;
}
