#include <bits/stdc++.h>
using namespace std;
const int N = 25, P = 1000000007;
using ll = long long;
int n, m, q, l;
struct Matrix {
  ll a[N][N] = {};
  ll *operator[](const size_t &s) { return a[s]; }
  const ll *operator[](const size_t &s) const { return a[s]; }
};
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  for (int i = 1; i <= l; i++)
    for (int j = 1; j <= l; j++)
      for (int k = 1; k <= l; k++)
        c[i][j] = (c[i][j] + a[i][k] * b[k][j] % P) % P;
  return c;
}
inline void output(Matrix &a) {
  for (int i = 1; i <= l; i++) {
    for (int j = 1; j <= l; j++) cout << a[i][j] << ' ';
    cout << endl;
  }
}
Matrix qpow(Matrix a, int b) {
  Matrix ret;
  for (int i = 1; i <= l; i++) ret[i][i] = 1;
  while (b) {
    if (b & 1) {
      ret = ret * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ret;
}
bool vis[N][N];
int main() {
  cin >> n >> m >> q;
  l = n * m;
  Matrix ans, cur;
  ans[1][1] = 1;
  int tp, x, y, t, lt = 1;
  for (int _ = 1; _ <= q; _++) {
    cin >> tp >> x >> y >> t;
    for (int i = 1; i <= l; i++)
      for (int j = i; j <= l; j++) {
        int x1 = (i - 1) / m + 1, y1 = (i - 1) % m + 1;
        int x2 = (j - 1) / m + 1, y2 = (j - 1) % m + 1;
        if (!vis[x1][y1] && !vis[x2][y2] && abs(x1 - x2) + abs(y1 - y2) < 2)
          cur[i][j] = cur[j][i] = 1;
        else
          cur[i][j] = cur[j][i] = 0;
      }
    ans = ans * qpow(cur, t - lt);
    if (tp == 1)
      cout << ans[1][(x - 1) * m + y] << endl;
    else if (tp == 2)
      ans[1][(x - 1) * m + y] = 0, vis[x][y] = 1;
    else if (tp == 3)
      ans[1][(x - 1) * m + y] = 0, vis[x][y] = 0;
    lt = t;
  }
  return 0;
}
