#include <bits/stdc++.h>
using namespace std;
long double EPS = (long double)1e-11L;
const double PI = 3.141592653589793238462;
const int INF = 1e9 + 7;
const long long LINF = 1e18 + 7;
const int MOD = 1e9 + 7;
const int S = 21;
int n, m, s;
vector<long long> bad, ans;
vector<vector<long long> > T;
vector<vector<long long> > mult(const vector<vector<long long> >& a,
                                const vector<vector<long long> >& b) {
  vector<vector<long long> > c(s, vector<long long>(s));
  for (int i = 0; i < (int)(s); ++i) {
    for (int j = 0; j < (int)(s); ++j) {
      for (int k = 0; k < (int)(s); ++k) {
        c[i][j] = (c[i][j] + a[i][k] * b[k][j] % MOD) % MOD;
      }
    }
  }
  return c;
}
vector<vector<long long> > binPow(int b) {
  vector<vector<long long> > res(s, vector<long long>(s));
  for (int i = 0; i < (int)(s); ++i) {
    for (int j = 0; j < (int)(s); ++j) {
      res[i][j] = i == j;
    }
  }
  vector<vector<long long> > a = T;
  for (int i = 0; i < (int)(s); ++i) {
    if (bad[i]) {
      for (int j = 0; j < (int)(s); ++j) {
        a[j][i] = 0;
      }
    }
  }
  while (b) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
void upd(int dt) {
  vector<vector<long long> > res = binPow(dt);
  vector<long long> nAns(s);
  for (int i = 0; i < (int)(s); ++i) {
    for (int j = 0; j < (int)(s); ++j) {
      nAns[j] = (nAns[j] + ans[i] * res[i][j] % MOD) % MOD;
    }
  }
  ans = nAns;
}
int main() {
  int q;
  cin >> n >> m >> q;
  s = n * m;
  T.assign(s, vector<long long>(s));
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = 0; j < (int)(m); ++j) {
      int from = i * m + j;
      for (int q = 0; q < (int)(n); ++q) {
        for (int k = 0; k < (int)(m); ++k) {
          if ((i - q) * (i - q) + (j - k) * (j - k) <= 1) {
            int to = q * m + k;
            T[from][to] = 1;
          }
        }
      }
    }
  }
  int curt = 1;
  ans.resize(s), bad.resize(s);
  ans[0] = 1;
  for (int i = 0; i < (int)(q); ++i) {
    int tp, x, y, t;
    cin >> tp >> x >> y >> t;
    x--, y--;
    upd(t - curt);
    curt = t;
    int p = x * m + y;
    if (tp == 1) {
      cout << ans[p] << endl;
      continue;
    }
    if (tp == 2) {
      bad[p] = 1;
      ans[p] = 0;
      continue;
    }
    bad[p] = 0;
  }
}
