#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
bool cat[25][25];
int n, m, q;
class Matrix {
 public:
  long long matrix[40][40];
  int sz;
} way, dp;
Matrix mul(Matrix a, Matrix b) {
  Matrix ans;
  ans.sz = a.sz;
  memset(ans.matrix, 0, sizeof ans.matrix);
  for (int i = 0; i < a.sz; i++)
    for (int j = 0; j < a.sz; j++)
      for (int k = 0; k < a.sz; k++)
        ans.matrix[i][j] =
            (ans.matrix[i][j] + a.matrix[i][k] * b.matrix[k][j]) % mod;
  return ans;
}
Matrix qpow(Matrix mat, int k) {
  Matrix ans = mat;
  k--;
  for (; k; k >>= 1, mat = mul(mat, mat))
    if (k & 1) ans = mul(ans, mat);
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  int tt = 1;
  dp.matrix[0][0] = 1;
  dp.sz = way.sz = n * m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 4; k++) {
        int xx = i + dx[k], yy = j + dy[k];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
        way.matrix[i * m + j][xx * m + yy] = 1;
      }
      way.matrix[i * m + j][i * m + j] = 1;
    }
  }
  for (int i = 0; i < q; i++) {
    int op, x, y, t;
    scanf("%d%d%d%d", &op, &x, &y, &t);
    x--, y--;
    if (op == 1) {
      dp = mul(dp, qpow(way, t - tt));
      printf("%lld\n", dp.matrix[0][x * m + y]);
    } else if (op == 2) {
      dp = mul(dp, qpow(way, t - tt));
      dp.matrix[0][x * m + y] = 0;
      way.matrix[x * m + y][x * m + y] = 0;
      cat[x][y] = 1;
      for (int j = 0; j < 4; j++) {
        int xx = x + dx[j], yy = y + dy[j];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
        int id1 = x * m + y, id2 = xx * m + yy;
        way.matrix[id1][id2] = way.matrix[id2][id1] = 0;
      }
    } else {
      dp = mul(dp, qpow(way, t - tt));
      cat[x][y] = 0;
      way.matrix[x * m + y][x * m + y] = 1;
      for (int j = 0; j < 4; j++) {
        int xx = x + dx[j], yy = y + dy[j];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
        int id1 = x * m + y, id2 = xx * m + yy;
        if (cat[x][y] == 0 && cat[xx][yy] == 0)
          way.matrix[id1][id2] = way.matrix[id2][id1] = 1;
      }
    }
    tt = t;
  }
}
