#include <bits/stdc++.h>
using namespace std;
struct matrix {
  long long a[41][41];
} ans;
int n, m, q, tot;
long long safe(long long n) {
  if (n < 0) n += (((-n) / 1000000007 + 1) * 1000000007);
  if (n >= 1000000007) n %= 1000000007;
  return n;
}
matrix cal(matrix a, matrix b) {
  matrix ans;
  for (int i = 0; i < tot; i++)
    for (int j = 0; j < tot; j++) {
      ans.a[i][j] = 0;
      for (int k = 0; k < tot; k++)
        ans.a[i][j] = (ans.a[i][j] + safe(a.a[i][k] * b.a[k][j])) % 1000000007;
    }
  return ans;
}
matrix quickmod(matrix a, long long n) {
  matrix ans;
  memset(ans.a, 0, sizeof(ans.a));
  for (int i = 0; i < tot; i++) ans.a[i][i] = 1;
  while (n) {
    if (n % 2) ans = cal(ans, a);
    a = cal(a, a);
    n /= 2;
  }
  return ans;
}
long long cal(long long x, long long y) {
  if (x < 0 || x == n) return -1;
  if (y < 0 || y == m) return -1;
  return (x * m + y);
}
matrix v;
int pb(int x, int y) {
  int id = cal(x, y);
  if (id == -1) return 0;
  if (v.a[id][id] == 1) return 0;
  return 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  tot = n * m;
  long long pret = 1;
  matrix ans, a;
  memset(ans.a, 0, sizeof(ans.a));
  memset(a.a, 0, sizeof(a.a));
  memset(v.a, 0, sizeof(v.a));
  for (int i = 0; i < tot; i++) ans.a[i][i] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int id = cal(i, j);
      a.a[id][id] = 1;
      if (cal(i + 1, j) != -1) a.a[id][cal(i + 1, j)] = 1;
      if (cal(i - 1, j) != -1) a.a[id][cal(i - 1, j)] = 1;
      if (cal(i, j - 1) != -1) a.a[id][cal(i, j - 1)] = 1;
      if (cal(i, j + 1) != -1) a.a[id][cal(i, j + 1)] = 1;
    }
  for (int i = 0; i < q; i++) {
    long long tp, x, y, t;
    scanf("%lld%lld%lld%lld", &tp, &x, &y, &t);
    x--;
    y--;
    if (tp == 1) {
      ans = cal(ans, quickmod(a, t - pret));
      printf("%lld\n", ans.a[0][cal(x, y)]);
    }
    if (tp == 2) {
      ans = cal(ans, quickmod(a, t - pret));
      int id = cal(x, y);
      v.a[id][id] = 1;
      for (int j = 0; j < n; j++)
        for (int k = 0; k < m; k++)
          ans.a[cal(j, k)][id] = a.a[cal(j, k)][id] = a.a[id][cal(j, k)] = 0;
    }
    if (tp == 3) {
      ans = cal(ans, quickmod(a, t - pret));
      int id = cal(x, y);
      a.a[id][id] = 1;
      v.a[id][id] = 0;
      if (cal(x - 1, y) != -1 && pb(x - 1, y))
        a.a[id][cal(x - 1, y)] = a.a[cal(x - 1, y)][id] = 1;
      if (cal(x + 1, y) != -1 && pb(x + 1, y))
        a.a[id][cal(x + 1, y)] = a.a[cal(x + 1, y)][id] = 1;
      if (cal(x, y + 1) != -1 && pb(x, y + 1))
        a.a[id][cal(x, y + 1)] = a.a[cal(x, y + 1)][id] = 1;
      if (cal(x, y - 1) != -1 && pb(x, y - 1))
        a.a[id][cal(x, y - 1)] = a.a[cal(x, y - 1)][id] = 1;
    }
    pret = t;
  }
  return 0;
}
