#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long row, col, query;
int cat[25][25];
vector<vector<long long> > unit(long long n) {
  vector<vector<long long> > ret(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) ret[i][i] = 1;
  return ret;
}
vector<vector<long long> > matrixAdd(const vector<vector<long long> > &a,
                                     const vector<vector<long long> > &b) {
  long long n = a.size();
  long long m = a[0].size();
  vector<vector<long long> > ret(n, vector<long long>(m));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) ret[i][j] = (a[i][j] + b[i][j]) % mod;
  return ret;
}
vector<vector<long long> > matrixMul(const vector<vector<long long> > &a,
                                     const vector<vector<long long> > &b) {
  long long n = a.size();
  long long m = a[0].size();
  long long k = b[0].size();
  vector<vector<long long> > ret(n, vector<long long>(k));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < k; j++)
      for (long long p = 0; p < m; p++)
        ret[i][j] = (ret[i][j] + (long long)a[i][p] * b[p][j]) % mod;
  return ret;
}
vector<vector<long long> > matrixPow(const vector<vector<long long> > &a,
                                     long long p) {
  if (p == 0) return unit(a.size());
  if (p & 1) return matrixMul(a, matrixPow(a, p - 1));
  return matrixPow(matrixMul(a, a), p / 2);
}
long long getId(long long r, long long c) { return col * r + c; }
bool isCan(long long y, long long x) {
  if (y >= 0 && y < row && x >= 0 && x < col) return true;
  return false;
}
long long dy[4] = {0, 0, 1, -1};
long long dx[4] = {1, -1, 0, 0};
void addMatrix(long long y, long long x, vector<vector<long long> > &m) {
  long long id = getId(y, x);
  m[id][id] = 1;
  for (long long k = 0; k < 4; k++) {
    long long ny = y + dy[k];
    long long nx = x + dx[k];
    if (isCan(ny, nx)) {
      long long nid = getId(ny, nx);
      if (cat[ny][nx] == 0 && cat[y][x] == 0) {
        m[nid][id] = 1;
        m[id][nid] = 1;
      }
    }
  }
}
void eraseMatrix(long long y, long long x, vector<vector<long long> > &m) {
  long long id = getId(y, x);
  m[id][id] = 0;
  for (long long k = 0; k < 4; k++) {
    long long ny = y + dy[k];
    long long nx = x + dx[k];
    if (isCan(ny, nx)) {
      long long nid = getId(ny, nx);
      m[nid][id] = 0;
      m[id][nid] = 0;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> row >> col >> query;
  long long n = row * col;
  vector<vector<long long> > base;
  vector<vector<long long> > m(n, vector<long long>(n));
  vector<vector<long long> > init(n, vector<long long>(1));
  init[0][0] = 1;
  long long cur = 1;
  base = m;
  for (long long y = 0; y < row; y++) {
    for (long long x = 0; x < col; x++) {
      addMatrix(y, x, base);
    }
  }
  vector<vector<long long> > A = init;
  for (long long i = 0; i < query; i++) {
    long long type, r, c, t;
    cin >> type >> r >> c >> t;
    r--, c--;
    long long diff = t - cur;
    if (type == 1) {
      vector<vector<long long> > temp = matrixPow(base, diff);
      A = matrixMul(temp, A);
      long long id = getId(r, c);
      long long ans = A[id][0];
      cout << ans << "\n";
    } else if (type == 2) {
      vector<vector<long long> > temp = matrixPow(base, diff);
      A = matrixMul(temp, A);
      A[getId(r, c)][0] = 0;
      cat[r][c] = 1;
      eraseMatrix(r, c, base);
    } else {
      vector<vector<long long> > temp = matrixPow(base, diff);
      ;
      A = matrixMul(temp, A);
      cat[r][c] = 0;
      addMatrix(r, c, base);
    }
    cur = t;
  }
}
