#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
struct Matrix {
  int mat[20][20];
};
int n, m, q, sz;
Matrix M, I;
int cats[20];
inline void add_edge(int i, int j, int i2, int j2) {
  M.mat[i * m + j][i2 * m + j2] = 1;
}
inline void remove_edge(int i, int j, int i2, int j2) {
  M.mat[i * m + j][i2 * m + j2] = 0;
}
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
Matrix matmul(Matrix a, Matrix b) {
  Matrix c;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      c.mat[i][j] = 0;
      for (int k = 0; k < sz; k++) {
        if (cats[k]) continue;
        c.mat[i][j] =
            (c.mat[i][j] + (long long)a.mat[i][k] * b.mat[k][j]) % MOD;
      }
    }
  }
  return c;
}
Matrix matexp(Matrix a, int b) {
  if (b == 0) return I;
  if (b & 1) {
    return matmul(a, matexp(a, b - 1));
  }
  Matrix tmp = matexp(a, b / 2);
  return matmul(tmp, tmp);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> q;
  sz = n * m;
  for (int i = 0; i < sz; i++)
    for (int j = 0; j < sz; j++) I.mat[i][j] = (i == j);
  memset(M.mat, 0, sizeof M.mat);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      add_edge(i, j, i, j);
      for (int k = 0; k < 4; k++) {
        int i2 = i + dx[k];
        int j2 = j + dy[k];
        if (i2 < 0 || i2 >= n || j2 < 0 || j2 >= m) continue;
        add_edge(i, j, i2, j2);
      }
    }
  }
  Matrix res = I;
  int cur = 1;
  while (q--) {
    int type, i, j, t;
    cin >> type >> i >> j >> t;
    i--;
    j--;
    res = matmul(res, matexp(M, t - cur));
    if (type == 1) {
      cout << res.mat[0][i * m + j] << "\n";
    } else if (type == 2) {
      remove_edge(i, j, i, j);
      for (int k = 0; k < 4; k++) {
        int i2 = i + dx[k];
        int j2 = j + dy[k];
        if (i2 < 0 || i2 >= n || j2 < 0 || j2 >= m) continue;
        remove_edge(i2, j2, i, j);
        remove_edge(i, j, i2, j2);
      }
      cats[i * m + j] = 1;
    } else {
      add_edge(i, j, i, j);
      for (int k = 0; k < 4; k++) {
        int i2 = i + dx[k];
        int j2 = j + dy[k];
        if (i2 < 0 || i2 >= n || j2 < 0 || j2 >= m) continue;
        add_edge(i, j, i2, j2);
        add_edge(i2, j2, i, j);
      }
      cats[i * m + j] = 0;
    }
    cur = t;
  }
  return 0;
}
