#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct Mat {
  vector<vector<int> > M;
  Mat(int n = 0, int m = 0) { M.assign(n, vector<int>(m, 0)); }
  vector<int>& operator[](int x) { return M[x]; }
  int size() { return M.size(); }
};
Mat operator*(Mat a, Mat b) {
  int m = a.size(), n = b.size(), p = b[0].size();
  Mat c = Mat(m, p);
  for (int i = (int)(0); i < (int)(m); i++)
    for (int j = (int)(0); j < (int)(p); j++)
      for (int k = (int)(0); k < (int)(n); k++)
        c[i][j] = (c[i][j] + (1ll * a[i][k] * b[k][j]) % mod) % mod;
  return c;
}
Mat pw(Mat a, int n) {
  int m = a.size();
  Mat r = Mat(m, m);
  for (int i = (int)(0); i < (int)(m); i++) r[i][i] = 1;
  for (int i = 0; (1ll << i) <= n; i++) {
    if (n & (1ll << i)) r = r * a;
    a = a * a;
  }
  return r;
}
int n, m, q, sz;
Mat f, base;
const int dx[] = {0, 0, 0, -1, 1}, dy[] = {0, 1, -1, 0, 0};
bool outside(int x, int y) { return x < 0 || y < 0 || x >= n || y >= m; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  sz = n * m;
  base = Mat(sz, sz);
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(m); j++) {
      for (int k = (int)(0); k < (int)(5); k++) {
        int x = i + dx[k], y = j + dy[k];
        if (outside(x, y)) continue;
        base[x * m + y][i * m + j] = 1;
      }
    }
  f = Mat(1, sz);
  f[0][0] = 1;
  int cur = 1;
  while (q--) {
    int p, x, y, t;
    cin >> p >> x >> y >> t;
    x--;
    y--;
    f = f * pw(base, t - cur - 1);
    if (p == 2) {
      for (int i = (int)(0); i < (int)(5); i++) {
        int X = x + dx[i], Y = y + dy[i];
        if (outside(X, Y)) continue;
        base[X * m + Y][x * m + y] = 0;
      }
    }
    f = f * base;
    if (p == 1) cout << f[0][x * m + y] << endl;
    cur = t;
    if (p == 3) {
      for (int i = (int)(0); i < (int)(5); i++) {
        int X = x + dx[i], Y = y + dy[i];
        if (outside(X, Y)) continue;
        base[X * m + Y][x * m + y] = 1;
      }
    }
  }
}
