#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int sz;
struct Matrix {
  long long x[22][22];
  void print() {
    for (int i = 0, _a = (sz); i < _a; i++) {
      for (int j = 0, _a = (sz); j < _a; j++) cout << x[i][j] << ' ';
      cout << endl;
    }
    cout << endl;
  }
} A, I;
struct Vector {
  long long x[22];
  void print() {
    {
      cout << "x"
           << " = ";
      for (int _ = 0, _a = (sz); _ < _a; _++) cout << x[_] << ' ';
      cout << endl;
    };
  }
} f;
Vector update(const Vector& f, const Matrix& A) {
  Vector res;
  for (int i = 0, _a = (sz); i < _a; i++) {
    res.x[i] = 0;
    for (int j = 0, _a = (sz); j < _a; j++)
      res.x[i] = (res.x[i] + A.x[i][j] * f.x[j]) % MOD;
  }
  return res;
}
Matrix operator*(const Matrix& a, const Matrix& b) {
  Matrix res;
  for (int i = 0, _a = (sz); i < _a; i++)
    for (int j = 0, _a = (sz); j < _a; j++) {
      res.x[i][j] = 0;
      for (int k = 0, _a = (sz); k < _a; k++)
        res.x[i][j] = (res.x[i][j] + a.x[i][k] * b.x[k][j]) % MOD;
    }
  return res;
}
Matrix power(const Matrix& a, int k) {
  if (k == 0) return I;
  if (k == 1) return a;
  Matrix mid = power(a, k >> 1);
  mid = mid * mid;
  if (k & 1) return mid * a;
  return mid;
}
const int MN = 22;
int m, n, q, id[MN][MN];
const int di[5] = {-1, 1, 0, 0, 0};
const int dj[5] = {0, 0, -1, 1, 0};
bool outside(int u, int v) { return u < 1 || v < 1 || u > m || v > n; }
void init() {
  int cur = 0;
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++) id[i][j] = cur++;
  memset(I.x, 0, sizeof I.x);
  memset(A.x, 0, sizeof A.x);
  sz = m * n;
  for (int i = 0, _a = (sz); i < _a; i++) I.x[i][i] = 1;
  for (int i = (1), _b = (m); i <= _b; i++)
    for (int j = (1), _b = (n); j <= _b; j++) {
      for (int dir = 0, _a = (5); dir < _a; dir++) {
        int ii = i + di[dir], jj = j + dj[dir];
        if (outside(ii, jj)) continue;
        A.x[id[i][j]][id[ii][jj]] = 1;
      }
    }
}
int main() {
  ios ::sync_with_stdio(false);
  while (cin >> m >> n >> q) {
    init();
    memset(f.x, 0, sizeof f.x);
    f.x[0] = 1;
    int cur_time = 1;
    while (q--) {
      int typ;
      cin >> typ;
      int x, y, t;
      cin >> x >> y >> t;
      Matrix up = power(A, t - 1 - cur_time);
      f = update(f, up);
      if (typ == 2) {
        for (int dir = 0, _a = (5); dir < _a; dir++) {
          int xx = x + di[dir], yy = y + dj[dir];
          if (outside(xx, yy)) continue;
          A.x[id[x][y]][id[xx][yy]] = 0;
        }
      }
      f = update(f, A);
      if (typ == 1) {
        cout << (int)f.x[id[x][y]] << '\n';
      }
      cur_time = t;
      if (typ == 3) {
        for (int dir = 0, _a = (5); dir < _a; dir++) {
          int xx = x + di[dir], yy = y + dj[dir];
          if (outside(xx, yy)) continue;
          A.x[id[x][y]][id[xx][yy]] = 1;
        }
      }
    }
  }
}
