#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 1e4 + 5;
int add(int a, int b) { return (a + b) % MOD; }
int multiply(int a, int b) { return 1LL * a * b % MOD; }
struct mat {
  int a[20][20], h, w;
  mat(int h = 0, int w = 0) : h(h), w(w) { memset(a, 0, sizeof(a)); }
};
mat operator*(const mat &a, const mat &b) {
  mat res = mat(a.h, b.w);
  for (int k = 0; k < a.w; ++k) {
    for (int i = 0; i < a.h; ++i) {
      for (int j = 0; j < b.w; ++j) {
        res.a[i][j] = add(res.a[i][j], multiply(a.a[i][k], b.a[k][j]));
      }
    }
  }
  return res;
}
mat operator^(mat a, int n) {
  mat ans = mat(a.h, a.w);
  for (int i = 0; i < a.h; ++i) ans.a[i][i] = 1;
  while (n) {
    if (n & 1) ans = ans * a;
    a = a * a;
    n >>= 1;
  }
  return ans;
}
bool cat[25][25];
mat build(int n, int m) {
  mat ans = mat(n * m, n * m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (cat[i][j]) continue;
      int tmp = i * m + j;
      ans.a[tmp][tmp] = 1;
      if (i > 0 && !cat[i - 1][j]) ans.a[(i - 1) * m + j][tmp] = 1;
      if (i < n - 1 && !cat[i + 1][j]) ans.a[(i + 1) * m + j][tmp] = 1;
      if (j > 0 && !cat[i][j - 1]) ans.a[i * m + j - 1][tmp] = 1;
      if (j < m - 1 && !cat[i][j + 1]) ans.a[i * m + j + 1][tmp] = 1;
    }
  }
  return ans;
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  mat ans = mat(1, n * m);
  ans.a[0][0] = 1;
  int last = 1;
  for (int i = 1; i <= q; ++i) {
    int type, x, y, t;
    scanf("%d%d%d%d", &type, &x, &y, &t);
    x--;
    y--;
    ans = ans * (build(n, m) ^ (t - last));
    last = t;
    if (type == 1) {
      printf("%d\n", ans.a[0][x * m + y]);
    } else if (type == 2) {
      cat[x][y] = 1;
    } else {
      cat[x][y] = 0;
    }
  }
  return 0;
}
