#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) ret = (ret * b) % mod;
    b = (b * b) % mod;
    n >>= 1;
  }
  return (long long)ret;
}
using namespace std;
using namespace std;
long long Trans[21][21];
int idx[21][21], n, m, sz;
int dx[] = {0, -1, 1, 0, 0};
int dy[] = {0, 0, 0, -1, 1};
long long ans[21];
long long MOD = 1e9 + 7;
long long I[21][21];
long long temp[21][21];
bool mark[21];
bool chk(int x, int y) {
  if (x >= 0 && y >= 0 && y < m && x < n) return 1;
  return 0;
}
void mult(long long a[][21], long long b[][21]) {
  long long c[21][21];
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      c[i][j] = 0;
      for (int k = 0; k < sz; k++) {
        c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % MOD) % MOD;
      }
    }
  }
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) a[i][j] = c[i][j];
  }
}
void power_upd(int p) {
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      temp[i][j] = Trans[i][j];
    }
  }
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < sz; j++) {
      if (i == j)
        I[i][j] = 1;
      else
        I[i][j] = 0;
    }
  }
  while (p > 0) {
    if (p & 1) {
      mult(I, temp);
    }
    mult(temp, temp);
    p >>= 1;
  }
  long long d[21];
  for (int i = 0; i < sz; i++) {
    d[i] = 0;
    for (int j = 0; j < sz; j++) {
      d[i] = (d[i] + I[i][j] * ans[j]) % MOD;
    }
  }
  for (int i = 0; i < sz; i++) ans[i] = d[i];
}
int main() {
  int q;
  cin >> n >> m >> q;
  sz = n * m;
  int cur = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      idx[i][j] = cur++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 5; k++) {
        int ii = i + dx[k];
        int jj = j + dy[k];
        if (!chk(ii, jj)) continue;
        Trans[idx[i][j]][idx[ii][jj]] = 1;
        Trans[idx[ii][jj]][idx[i][j]] = 1;
      }
    }
  }
  cur = 1;
  ans[0] = 1;
  while (q--) {
    int x, y, t, ty;
    cin >> ty >> x >> y >> t;
    power_upd(t - cur);
    cur = t;
    x--;
    y--;
    if (ty == 1) {
      cout << ans[idx[x][y]] << endl;
    } else if (ty == 2) {
      int k = idx[x][y];
      for (int i = 0; i < sz; i++) {
        Trans[i][k] = 0;
        Trans[k][i] = 0;
      }
      ans[k] = 0;
      mark[k] = 1;
    } else if (ty == 3) {
      int k = idx[x][y];
      mark[k] = 0;
      for (int i = 0; i < 5; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (!chk(nx, ny)) continue;
        int nk = idx[nx][ny];
        if (!mark[nk]) Trans[k][nk] = Trans[nk][k] = 1;
      }
    }
  }
  return 0;
}
