#include <bits/stdc++.h>
using namespace std;
struct matrix {
  int mat[25][25];
  matrix() { memset(mat, 0, sizeof(mat)); }
  void print(int n) {
    int j, k;
    for (j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        printf("%d ", mat[j][k]);
      }
      printf("\n");
    }
  }
} A, B, C;
int rx[] = {0, 1, 0, -1, 0}, ry[] = {1, 0, -1, 0, 0};
int n, m;
bool mark[25];
matrix operator*(matrix a, matrix b) {
  matrix ans;
  int j, k, i;
  for (j = 1; j <= n * m; j++) {
    for (k = 1; k <= n * m; k++) {
      for (i = 1; i <= n * m; i++) {
        ans.mat[j][k] =
            (ans.mat[j][k] + 1LL * a.mat[j][i] * b.mat[i][k] % 1000000007) %
            1000000007;
      }
    }
  }
  return ans;
}
matrix operator^(matrix a, int b) {
  matrix t = a, ans;
  int j, k;
  for (j = 1; j <= n * m; j++) ans.mat[j][j] = 1;
  while (b) {
    if (b & 1) ans = ans * t;
    t = t * t;
    b >>= 1;
  }
  return ans;
}
bool check(int x, int y, int n, int m) {
  return x >= 1 && x <= n && y >= 1 && y <= m;
}
int main() {
  int q;
  scanf("%d%d%d", &n, &m, &q);
  int j, k, i;
  for (j = 1; j <= n; j++) {
    for (k = 1; k <= m; k++) {
      for (i = 0; i < 5; i++) {
        int x = j + rx[i], y = k + ry[i];
        if (!check(x, y, n, m)) continue;
        int id = k + (j - 1) * m, id1 = y + (x - 1) * m;
        B.mat[id][id1] = 1;
      }
    }
  }
  int pre = 1;
  for (j = 1; j <= 20; j++) A.mat[j][j] = 1;
  for (j = 0; j < q; j++) {
    int op, x, y, t;
    scanf("%d%d%d%d", &op, &x, &y, &t);
    for (k = 1; k <= n * m; k++) {
      for (i = 1; i <= n * m; i++) {
        if (mark[k] || mark[i])
          C.mat[k][i] = 0;
        else
          C.mat[k][i] = B.mat[k][i];
      }
    }
    A = A * (C ^ (t - pre));
    if (op == 1) {
      printf("%d\n", A.mat[1][y + (x - 1) * m]);
    } else if (op == 2)
      mark[y + (x - 1) * m] = 1;
    else
      mark[y + (x - 1) * m] = 0;
    pre = t;
  }
  return 0;
}
