#include <bits/stdc++.h>
using namespace std;
int n;
void mulmat(int c[][32], int a[][32], int b[][32]) {
  int t[32][32];
  memset(t, 0, sizeof(t));
  for (int i = 0, to = n; i < to; ++i)
    for (int j = 0, to = n; j < to; ++j)
      for (int k = 0, to = n; k < to; ++k)
        t[i][j] += (1LL * a[i][k] * b[k][j]) % 1000000007,
            t[i][j] %= 1000000007;
  memcpy(c, t, sizeof(t));
}
void powmat(int c[][32], int a[][32], int e) {
  int t[32][32], r[32][32];
  memcpy(t, a, sizeof(t));
  memset(r, 0, sizeof(r));
  for (int i = 0, to = n; i < to; ++i) r[i][i] = 1;
  while (e) {
    if (e & 1) mulmat(r, r, t);
    e >>= 1;
    mulmat(t, t, t);
  }
  memcpy(c, r, sizeof(r));
}
int x[32][32], ox[32][32], w[32][32], w2[32][32];
int ni, nj, q;
int id(int i, int j) {
  if (i < 0 || j < 0 || i >= ni || j >= nj) return 31;
  return i * nj + j;
}
int main() {
  scanf("%d%d%d", &ni, &nj, &q);
  n = ni * nj;
  for (int i = 0, to = ni; i < to; ++i) {
    for (int j = 0, to = nj; j < to; ++j) {
      ox[id(i, j)][id(i, j)] = 1;
      ox[id(i, j)][id(i + 1, j)] = 1;
      ox[id(i, j)][id(i - 1, j)] = 1;
      ox[id(i, j)][id(i, j + 1)] = 1;
      ox[id(i, j)][id(i, j - 1)] = 1;
    }
  }
  memcpy(x, ox, sizeof(x));
  for (int i = 0, to = n; i < to; ++i) w[i][i] = 1;
  int t = 1;
  while (q--) {
    int o, a, b, tt;
    scanf("%d%d%d%d", &o, &a, &b, &tt);
    a = id(a - 1, b - 1);
    if (o == 2) tt--;
    powmat(w2, x, tt - t);
    mulmat(w, w, w2);
    if (o == 1) {
      printf("%d\n", w[0][a]);
    } else if (o == 2) {
      for (int i = 0, to = n; i < to; ++i) x[i][a] = 0;
    } else {
      for (int i = 0, to = n; i < to; ++i) x[i][a] = ox[i][a];
    }
    t = tt;
  }
  return 0;
}
