#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, m, q, t;
int g[(20 + 10)][(20 + 10)], tmp[(20 + 10)][(20 + 10)],
    ret[(20 + 10)][(20 + 10)], ans[(20 + 10)][(20 + 10)],
    gg[(20 + 10)][(20 + 10)];
int s[(20 + 10)][(20 + 10)];
int dx[] = {-1, 0, 1, 0, 0};
int dy[] = {0, -1, 0, 1, 0};
bool out(int x, int y) { return x < 0 || x >= n || y < 0 || y >= m; }
void add(int &u, int v) {
  u += v;
  if (u >= 1000000007) u -= 1000000007;
}
void mul(int a[(20 + 10)][(20 + 10)], int b[(20 + 10)][(20 + 10)]) {
  memset(tmp, 0, sizeof tmp);
  for (int i = 0; i < t; ++i) {
    for (int j = 0; j < t; ++j) {
      for (int k = 0; k < t; ++k) {
        add(tmp[i][j], (long long)a[i][k] * b[k][j] % 1000000007);
      }
    }
  }
  memcpy(a, tmp, sizeof tmp);
}
void qpow(int a[(20 + 10)][(20 + 10)], int k) {
  memset(ret, 0, sizeof ret);
  for (int i = 0; i < t; ++i) ret[i][i] = 1;
  while (k) {
    if (k & 1) mul(ret, a);
    mul(a, a);
    k >>= 1;
  }
}
int get(int x, int y) { return x * m + y; }
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      s[i][j] = 1;
      for (int k = 0; k < 5; ++k) {
        int x = i + dx[k], y = j + dy[k];
        if (out(x, y)) continue;
        g[get(i, j)][get(x, y)] = 1;
      }
    }
  }
  t = n * m;
  for (int i = 0; i < t; ++i) ans[i][i] = 1;
  int last = 1;
  while (q--) {
    int tp, x, y, t;
    scanf("%d%d%d%d", &tp, &x, &y, &t);
    --x, --y;
    memcpy(gg, g, sizeof g);
    qpow(gg, t - last);
    last = t;
    mul(ans, ret);
    if (tp == 1)
      printf("%d\n", ans[get(0, 0)][get(x, y)]);
    else {
      if (tp == 3) s[x][y] = 1;
      for (int i = 0; i < 5; ++i) {
        int nx = x + dx[i], ny = y + dy[i];
        if (out(nx, ny) || s[nx][ny] == 0) continue;
        g[get(x, y)][get(nx, ny)] = tp == 2 ? 0 : 1;
        g[get(nx, ny)][get(x, y)] = tp == 2 ? 0 : 1;
      }
      if (tp == 2) s[x][y] = 0;
    }
  }
}
