#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
struct Matrix {
  int c[25][25];
} res, tmp;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int vis[25][25];
int n, m, q;
Matrix Mul(Matrix A, Matrix B) {
  Matrix res;
  for (int i = 1; i <= n * m; i++) {
    for (int j = 1; j <= n * m; j++) {
      res.c[i][j] = 0;
      for (int k = 1; k <= n * m; k++) {
        res.c[i][j] = (res.c[i][j] + (long long)A.c[i][k] * B.c[k][j]) % M;
      }
    }
  }
  return res;
}
Matrix Solve(Matrix A, int n) {
  while (n) {
    if (n & 1) {
      A = Mul(tmp, A);
    }
    tmp = Mul(tmp, tmp);
    n >>= 1;
  }
  return A;
}
int GetId(int x, int y) { return (x - 1) * m + y; }
int main() {
  scanf("%d%d%d", &n, &m, &q);
  Matrix pre;
  memset(pre.c, 0, sizeof(pre.c));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      pre.c[GetId(i, j)][GetId(i, j)] = 1;
      int st, et;
      for (int k = 0; k < 4; k++) {
        st = i + dir[k][0];
        et = j + dir[k][1];
        if (st >= 1 && et >= 1 && st <= n && et <= m) {
          pre.c[GetId(i, j)][GetId(st, et)] = 1;
        }
      }
    }
  }
  tmp = pre;
  memset(res.c, 0, sizeof(res.c));
  res.c[1][1] = 1;
  memset(vis, 0, sizeof(vis));
  int pre_t = 1;
  while (q--) {
    int tp, x, y, t;
    scanf("%d%d%d%d", &tp, &x, &y, &t);
    if (tp == 1) {
      res = Solve(res, t - pre_t);
      pre_t = t;
      tmp = pre;
      printf("%d\n", res.c[GetId(x, y)][1]);
    } else if (tp == 2) {
      res = Solve(res, t - pre_t);
      pre_t = t;
      res.c[GetId(x, y)][1] = 0;
      pre.c[GetId(x, y)][GetId(x, y)] = 0;
      for (int k = 0; k < 4; k++) {
        int st, et;
        st = x + dir[k][0];
        et = y + dir[k][1];
        if (st >= 1 && et >= 1 && st <= n && et <= m) {
          pre.c[GetId(x, y)][GetId(st, et)] = 0;
          pre.c[GetId(st, et)][GetId(x, y)] = 0;
        }
      }
      tmp = pre;
      vis[x][y] = 1;
    } else {
      res = Solve(res, t - pre_t);
      pre_t = t;
      res.c[GetId(x, y)][1] = 0;
      pre.c[GetId(x, y)][GetId(x, y)] = 1;
      vis[x][y] = 0;
      for (int k = 0; k < 4; k++) {
        int st, et;
        st = x + dir[k][0];
        et = y + dir[k][1];
        if (st >= 1 && et >= 1 && st <= n && et <= m && !vis[st][et]) {
          pre.c[GetId(st, et)][GetId(x, y)] = 1;
          pre.c[GetId(x, y)][GetId(st, et)] = 1;
        }
      }
      tmp = pre;
    }
  }
}
