#include <bits/stdc++.h>
using namespace std;
long long modpow(long long x, long long p, long long M) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = ret * x % M;
    x = x * x % M;
    p /= 2;
  }
  return ret;
}
long long n, m, N;
long long dp[2][25];
long long mark[50][50];
vector<vector<long long> > cnt;
vector<vector<long long> > mult(vector<vector<long long> > a,
                                vector<vector<long long> > b) {
  vector<vector<long long> > ret(N, vector<long long>(N, 0));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      ret[i][j] = 0;
      for (int k = 0; k < N; k++)
        ret[i][j] = (ret[i][j] + a[i][k] * b[k][j] % 1000000007) % 1000000007;
    }
  return ret;
}
vector<vector<long long> > matpow(vector<vector<long long> > x, long long p) {
  vector<vector<long long> > ret(N, vector<long long>(N, 0));
  for (int i = 0; i < N; i++) ret[i][i] = 1;
  while (p) {
    if (p & 1) ret = mult(ret, x);
    x = mult(x, x);
    p /= 2;
  }
  return ret;
}
void update(int cur, int prv) {
  for (int i = 0; i < N; i++) {
    dp[cur][i] = 0;
    for (int j = 0; j < N; j++)
      dp[cur][i] = (dp[cur][i] + dp[prv][j] * cnt[i][j]) % 1000000007;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  N = n * m;
  long long q;
  cin >> q;
  long long tp, x, y, t;
  long long T = 1;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  int cur, prv;
  cur = 0;
  prv = 1;
  while (q--) {
    cin >> tp >> x >> y >> t;
    x--;
    y--;
    swap(cur, prv);
    vector<vector<long long> > tmp(N, vector<long long>(N, 0));
    for (int i = 0; i < N; i++)
      for (int j = i; j < N; j++) {
        int x1, y1, x2, y2;
        x1 = i / m;
        y1 = i % m;
        x2 = j / m;
        y2 = j % m;
        if (abs(x1 - x2) + abs(y1 - y2) <= 1 && !mark[x1][y1] &&
            !mark[x2][y2]) {
          tmp[i][j] = 1;
          tmp[j][i] = 1;
        }
      }
    cnt = matpow(tmp, t - T);
    update(cur, prv);
    if (tp == 1)
      cout << dp[cur][x * m + y] << "\n";
    else if (tp == 2)
      mark[x][y]++, dp[cur][x * m + y] = 0;
    else if (tp == 3)
      mark[x][y]--;
    T = t;
  }
  return 0;
}
