#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int inc[5][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, {0, 0}};
const int MAXN = 20, MOD = 1e9 + 7;
int add(int x, int y) { return (x + y) % MOD; }
void addeq(int &x, int y) { x = add(x, y); }
int mult(int x, int y) { return ll(x) * y % MOD; }
int N, M, S, Q;
bool inside(int x, int y) { return 0 <= x && x < N && 0 <= y && y < M; }
struct matrix {
  int data[MAXN][MAXN];
  int *operator[](int x) { return data[x]; }
  const int *operator[](int x) const { return data[x]; }
} zero, one;
matrix operator*(const matrix &m1, const matrix &m2) {
  matrix res = zero;
  for (int k = 0; k < S; k++) {
    for (int i = 0; i < S; i++) {
      for (int j = 0; j < S; j++) {
        addeq(res[i][j], mult(m1[i][k], m2[k][j]));
      }
    }
  }
  return res;
}
void operator*=(matrix &m1, const matrix &m2) { m1 = m1 * m2; }
matrix pow(matrix m1, int p) {
  matrix res = one;
  for (; p; p >>= 1) {
    if (p & 1) {
      res *= m1;
    }
    m1 *= m1;
  }
  return res;
}
matrix mat, trans;
void settrans(int i, int j, int val) {
  int ij = M * i + j;
  for (int k = 0; k < 5; k++) {
    int ni = i + inc[k][0], nj = j + inc[k][1];
    if (inside(ni, nj)) {
      trans[ij][M * ni + nj] = val;
    }
  }
}
int main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
  }
  scanf("%d %d %d", &N, &M, &Q);
  S = N * M;
  for (int i = 0; i < S; i++) {
    one[i][i] = 1;
  }
  mat = one;
  trans = zero;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      settrans(i, j, 1);
    }
  }
  int pt = 1;
  while (Q--) {
    int type, x, y, t;
    scanf("%d %d %d %d", &type, &x, &y, &t);
    x--;
    y--;
    mat = pow(trans, t - pt - 1) * mat;
    pt = t;
    if (type == 1) {
      mat = trans * mat;
      printf("%d\n", mat[M * x + y][0]);
    } else if (type == 2) {
      settrans(x, y, 0);
      mat = trans * mat;
    } else {
      mat = trans * mat;
      settrans(x, y, 1);
    }
  }
}
