#include <bits/stdc++.h>
using namespace std;
long long mat[411][411], cur[411][411];
long long y[411][411], c[411][411], d[411], ans[411];
int sz, mark[411], orgmat[411][411];
void multiply(long long a[][411], long long b[][411]) {
  int i, j, k;
  for (i = 0; i < sz; i++)
    for (j = 0; j < sz; j++) {
      c[i][j] = 0;
      for (k = 0; k < sz; k++)
        c[i][j] = (c[i][j] + (a[i][k] * b[k][j])) % 1000000007LL;
    }
  for (i = 0; i < sz; i++)
    for (j = 0; j < sz; j++) a[i][j] = c[i][j];
}
void mul(int b) {
  int i, j;
  for (i = 0; i < sz; i++)
    for (j = 0; j < sz; j++)
      if (i == j)
        cur[i][j] = 1;
      else
        cur[i][j] = 0;
  for (i = 0; i < sz; i++)
    for (j = 0; j < sz; j++) y[i][j] = mat[i][j];
  while (b > 0) {
    if (b & 1) multiply(cur, y);
    multiply(y, y);
    b /= 2;
  }
  for (i = 0; i < sz; i++) {
    d[i] = 0LL;
    for (j = 0; j < sz; j++)
      d[i] = (d[i] + (ans[j] * cur[j][i])) % 1000000007LL;
  }
  for (i = 0; i < sz; i++) ans[i] = d[i];
}
int main() {
  int n, m, q, i, j;
  scanf("%d %d %d", &n, &m, &q);
  sz = n * m;
  for (i = 0; i < sz; i++) {
    for (j = 0; j < sz; j++) {
      int r1 = i / m, r2 = j / m, c1 = i % m, c2 = j % m;
      if ((abs(r1 - r2) + abs(c1 - c2)) <= 1) mat[j][i] = 1, orgmat[i][j] = 1;
    }
  }
  ans[0] = 1LL;
  for (i = 1; i < sz; i++) ans[i] = 0LL;
  int prev = 1;
  while (q--) {
    int ty, i, j, t;
    scanf("%d %d %d %d", &ty, &i, &j, &t);
    mul(t - prev);
    prev = t;
    i--;
    j--;
    if (ty == 1)
      printf("%lld\n", ans[i * m + j]);
    else if (ty == 2) {
      i = i * m + j;
      for (int k = 0; k < sz; k++) mat[k][i] = 0;
      for (int k = 0; k < sz; k++) mat[i][k] = 0;
      mark[i] = 1;
      ans[i] = 0LL;
    } else {
      i = i * m + j;
      mark[i] = 0;
      for (int k = 0; k < sz; k++)
        if (mark[k] == 0) mat[k][i] = orgmat[i][k];
      for (int k = 0; k < sz; k++)
        if (mark[k] == 0) mat[i][k] = orgmat[i][k];
    }
  }
  return 0;
}
