#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
typedef long long arr[20][20];
int sz;
void mul(arr &a, arr &b) {
  arr c;
  memset(c, 0, sizeof(c));
  for (int i = 0; i < sz; i++)
    for (int j = 0; j < sz; j++) {
      for (int k = 0; k < sz; k++) c[i][j] += a[i][k] * b[k][j] % 1000000007;
      c[i][j] %= 1000000007;
    }
  for (int i = 0; i < sz; i++)
    for (int j = 0; j < sz; j++) a[i][j] = c[i][j];
}
void pow(arr &a, int n) {
  arr b;
  memset(b, 0, sizeof(b));
  for (int i = 0; i < sz; i++) b[i][i] = 1;
  while (n) {
    if (n & 1) mul(b, a);
    mul(a, a);
    n >>= 1;
  }
  for (int i = 0; i < sz; i++)
    for (int j = 0; j < sz; j++) a[i][j] = b[i][j];
}
arr a;
int v[21], n, m, d[][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
void cal(arr &a) {
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (v[i * m + j] == 0) {
        int first = i * m + j;
        a[first][first]++;
        for (int k = 0; k < 4; k++) {
          int ii = i + d[k][0], jj = j + d[k][1];
          if (ii >= 0 && ii < n && jj >= 0 && jj < m && !v[ii * m + jj]) {
            int second = ii * m + jj;
            a[first][second]++;
          }
        }
      }
}
long long b[22], c[22];
void mul1(long long *b, arr &a) {
  memset(c, 0, sizeof(c));
  for (int i = 0; i < sz; i++)
    if (b[i]) {
      for (int j = 0; j < sz; j++) c[j] += b[i] * a[i][j] % 1000000007;
    }
  for (int i = 0; i < sz; i++) {
    b[i] = c[i] % 1000000007;
  }
}
int main() {
  int T, i, j, k;
  int q;
  scanf("%d%d%d", &n, &m, &q);
  sz = n * m;
  memset(v, 0, sizeof(v));
  memset(b, 0, sizeof(b));
  b[0] = 1;
  int tt = 1, t, first, second, tp;
  while (q--) {
    scanf("%d%d%d%d", &tp, &first, &second, &t);
    first--, second--;
    cal(a);
    pow(a, t - tt - 1);
    mul1(b, a);
    if (tp == 2) v[first * m + second] = 1;
    memcpy(c, b, sizeof(c));
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++)
        if (b[i * m + j]) {
          for (k = 0; k < 4; k++) {
            int ii = i + d[k][0], jj = j + d[k][1];
            if (ii >= 0 && ii < n && jj >= 0 && jj < m && !v[ii * m + jj]) {
              int second = ii * m + jj;
              c[second] += b[i * m + j];
            }
          }
        }
    if (tp == 3)
      v[first * m + second] = 0;
    else if (tp == 2)
      c[first * m + second] = 0;
    for (i = 0; i < sz; i++) b[i] = c[i] % 1000000007;
    if (tp == 1) {
      printf("%d\n", (int)b[first * m + second]);
    }
    tt = t;
  }
  return 0;
}
