#include <bits/stdc++.h>
using namespace std;
int n, m;
int sz;
int q;
bool bl[25];
long long prod[25][25];
void matmult(long long a[][25], long long b[][25], long long dest[][25]) {
  memset(prod, 0, sizeof prod);
  for (int i = (1); i <= (signed)(sz); i++) {
    for (int j = (1); j <= (signed)(sz); j++) {
      for (int k = (1); k <= (signed)(sz); k++) {
        prod[i][j] += a[i][k] * b[k][j];
        prod[i][j] %= 1000000007;
      }
    }
  }
  for (int i = (1); i <= (signed)(sz); i++) {
    for (int j = (1); j <= (signed)(sz); j++) {
      dest[i][j] = prod[i][j];
    }
  }
}
long long mat[25][25];
long long ans[25][25];
void matexp(long long ex) {
  memset(ans, 0, sizeof ans);
  for (int i = (1); i <= (signed)(sz); i++) {
    ans[i][i] = 1;
  }
  while (ex > 0) {
    if (ex % 2 == 0) {
      matmult(mat, mat, mat);
      ex /= 2;
    } else {
      matmult(ans, mat, ans);
      ex--;
    }
  }
}
long long cur[25][25];
long long wtmoo[25][25];
vector<int> near[25];
int conv(int x, int y) { return x * m + y - m; }
int dx[5] = {0, 1, 0, -1, 0};
int dy[5] = {0, 0, 1, 0, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> q;
  sz = n * m;
  int pt = 1;
  for (int i = (1); i <= (signed)(sz); i++) wtmoo[i][i] = 1;
  for (int i = (1); i <= (signed)(n); i++) {
    for (int j = (1); j <= (signed)(m); j++) {
      int loc = conv(i, j);
      for (int dir = 0; dir < (signed)(5); dir++) {
        int nx = i + dx[dir], ny = j + dy[dir];
        if (nx <= 0 || ny <= 0 || nx > n || ny > m) continue;
        int loc2 = conv(nx, ny);
        near[loc].push_back(loc2);
        cur[loc][loc2] = 1;
      }
    }
  }
  for (int i = 0; i < (signed)(q); i++) {
    int ct, tp, x, y;
    cin >> tp >> x >> y >> ct;
    int loc = x * m + y - m;
    long long d = ct - pt;
    pt = ct;
    memcpy(mat, cur, sizeof mat);
    matexp(d);
    matmult(wtmoo, ans, wtmoo);
    if (tp == 1) {
      cout << wtmoo[1][loc] << "\n";
    } else if (tp == 2) {
      bl[loc] = true;
      for (auto u : near[loc]) {
        cur[u][loc] = 0;
        cur[loc][u] = 0;
      }
    } else if (tp == 3) {
      bl[loc] = false;
      for (auto u : near[loc]) {
        if (!bl[u]) {
          cur[u][loc] = 1;
          cur[loc][u] = 1;
        }
      }
    }
  }
  return 0;
}
