#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int maxm = maxn * 4 + 10;
const int inf = 1e9;
const long long mod = 1e9 + 7;
int getint() {
  char c;
  while ((c = getchar()) && !(c >= '0' && c <= '9') && c != '-')
    ;
  int ret = c - '0', sgn = 0;
  if (c == '-') sgn = 1, ret = 0;
  while ((c = getchar()) && c >= '0' && c <= '9') ret = ret * 10 + c - '0';
  if (sgn) ret = -ret;
  return ret;
}
struct matrix {
  int r, c;
  long long p[maxn][maxn];
  matrix() { memset(p, 0, sizeof(p)); }
  matrix operator*(matrix a) const {
    matrix ret;
    ret.r = r, ret.c = a.c;
    for (int k = 0; k < c; k++) {
      for (int i = 0; i < r; i++) {
        if (p[i][k] == 0) continue;
        for (int j = 0; j < a.c; j++) {
          ret.p[i][j] += (p[i][k] * a.p[k][j]) % mod;
          ret.p[i][j] %= mod;
        }
      }
    }
    return ret;
  }
  void show() {
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cout << p[i][j] << " ";
      }
      cout << endl;
    }
  }
};
matrix m_pow(matrix a, int k) {
  matrix ans;
  ans.r = ans.c = a.r;
  for (int i = 0; i < ans.r; i++) ans.p[i][i] = 1;
  while (k) {
    if (k & 1) ans = ans * a;
    a = a * a;
    k >>= 1;
  }
  return ans;
}
int dx[4] = {0, 0, -1, 1}, dy[4] = {-1, 1, 0, 0};
matrix mx;
int vis[maxn][maxn];
int n, m, t;
void update() {
  memset(mx.p, 0, sizeof(mx.p));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vis[i][j]) continue;
      mx.p[i * m + j][i * m + j] = 1;
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny]) {
          mx.p[i * m + j][nx * m + ny] = 1;
        }
      }
    }
  }
}
int main() {
  while (scanf("%d%d%d", &n, &m, &t) == 3) {
    memset(vis, 0, sizeof(vis));
    mx.r = mx.c = n * m;
    matrix st;
    st.r = n * m, st.c = 1;
    st.p[0][0] = 1;
    int cur = 1;
    while (t--) {
      int op = getint(), x = getint(), y = getint(), tt = getint();
      x--, y--;
      if (op == 1) {
        update();
        st = m_pow(mx, tt - cur) * st;
        cur = tt;
        cout << st.p[x * m + y][0] << endl;
      } else {
        update();
        st = m_pow(mx, tt - cur) * st;
        cur = tt;
        if (op == 2) st.p[x * m + y][0] = 0;
        vis[x][y] = op == 2;
      }
    }
  }
  return 0;
}
