#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int mod = 1e9 + 7;
int dx[] = {1, 0, -1, 0, 0};
int dy[] = {0, -1, 0, 1, 0};
int n, m, q;
struct matrix {
  int n, m, a[21][21];
  matrix() {
    n = m = 0;
    memset(a, 0, sizeof a);
  }
};
int sum(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int mult(int a, int b) { return (1ll * a * b) % mod; }
matrix operator*(matrix a, matrix b) {
  matrix ans;
  ans.n = a.n, ans.m = b.m;
  for (int i = 1; i <= ans.n; i++)
    for (int j = 1; j <= ans.m; j++)
      for (int k = 1; k <= a.m; k++)
        ans.a[i][j] = sum(ans.a[i][j], mult(a.a[i][k], b.a[k][j]));
  return ans;
}
matrix bp(matrix a, int n) {
  matrix ans;
  ans.n = ans.m = a.n;
  for (int i = 1; i <= ans.n; i++) ans.a[i][i] = 1;
  while (n) {
    if (n & 1) ans = ans * a;
    a = a * a;
    n >>= 1;
  }
  return ans;
}
bool valid(int x, int y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m) return 1;
  return 0;
}
int id(int x, int y) { return (x - 1) * m + y; }
int main() {
  scanf("%d%d%d", &n, &m, &q);
  matrix a, dp;
  dp.n = 1, dp.m = n * m;
  dp.a[1][1] = 1;
  a.n = a.m = n * m;
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++)
      for (int i = 0; i < 5; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (valid(nx, ny))
          a.a[id(x, y)][id(nx, ny)] = a.a[id(nx, ny)][id(x, y)] = 1;
      }
  for (int i = 1, type, x, y, t, prev = 1; i <= q; i++) {
    scanf("%d%d%d%d", &type, &x, &y, &t);
    dp = dp * bp(a, t - prev);
    prev = t;
    if (type == 1) printf("%d\n", dp.a[1][id(x, y)]);
    if (type == 2)
      for (int j = 0; j < 5; j++) {
        int nx = x + dx[j];
        int ny = y + dy[j];
        if (valid(nx, ny))
          a.a[id(nx, ny)][id(x, y)] = a.a[id(x, y)][id(nx, ny)] = 0;
      }
    if (type == 3)
      for (int j = 0; j < 5; j++) {
        int nx = x + dx[j];
        int ny = y + dy[j];
        if (valid(nx, ny) &&
            (a.a[id(nx, ny)][id(nx, ny)] != 0 || id(nx, ny) == id(x, y)))
          a.a[id(nx, ny)][id(x, y)] = a.a[id(x, y)][id(nx, ny)] = 1;
      }
  }
  return 0;
}
