#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m, q;
int N;
vector<int> G[22];
struct Mat {
  int a[22][22];
  Mat operator*(const Mat& x) const {
    Mat rep;
    memset(rep.a, 0, sizeof(rep.a));
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        for (int k = 0; k < N; k++) {
          rep.a[i][j] += 1LL * a[i][k] * x.a[k][j] % p;
          if (rep.a[i][j] >= p) rep.a[i][j] -= p;
        }
      }
    }
    return rep;
  }
} danwei, ori;
Mat powmod(Mat x, int y) {
  Mat ret = danwei;
  while (y) {
    if (y & 1) ret = ret * x;
    x = x * x;
    y >>= 1;
  }
  return ret;
}
int has[22];
int getid(int x, int y) { return x * m + y; }
int main() {
  scanf("%d%d%d", &n, &m, &q);
  N = n * m;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) danwei.a[i][j] = i == j;
  ori = danwei;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int id = getid(i, j);
      for (int di = 0; di < 4; di++) {
        int ni = i + d[di][0];
        int nj = j + d[di][1];
        if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
          G[id].push_back(getid(ni, nj));
          ori.a[id][getid(ni, nj)] = 1;
        }
      }
    }
  }
  Mat cur = danwei;
  int tl = 1;
  while (q--) {
    int ty, x, y, t;
    scanf("%d%d%d%d", &ty, &x, &y, &t);
    x--, y--;
    if (ty == 1) {
      cur = cur * powmod(ori, t - tl);
      tl = t;
      printf("%d\n", cur.a[0][getid(x, y)]);
    }
    if (ty == 2) {
      cur = cur * powmod(ori, t - 1 - tl);
      int id = getid(x, y);
      has[id] = 1;
      for (int j = 0; j < G[id].size(); j++) {
        ori.a[G[id][j]][id] = 0;
      }
      ori.a[id][id] = 0;
      tl = t - 1;
    }
    if (ty == 3) {
      cur = cur * powmod(ori, t - tl);
      int id = getid(x, y);
      has[id] = 0;
      for (int j = 0; j < G[id].size(); j++) {
        if (!has[G[id][j]]) ori.a[id][G[id][j]] = 1;
        ori.a[G[id][j]][id] = 1;
      }
      ori.a[id][id] = 1;
      tl = t;
    }
  }
}
