#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const int C = 21;
int n, m, cat[C];
int dx[] = {+1, -1, 0, 0, 0};
int dy[] = {0, 0, +1, -1, 0};
int mod(long long x) { return (x % 1000000007); }
struct matris {
  int A[C][C];
  matris() { memset(A, 0, sizeof A); }
  matris operator*(matris B) const {
    matris C;
    for (int i = 1; i <= n * m; i++)
      for (int j = 1; j <= n * m; j++)
        for (int k = 1; k <= n * m; k++)
          C.A[i][j] = mod(C.A[i][j] + mod(A[i][k] * 1LL * B.A[k][j]));
    return C;
  }
} cur;
int id(int x, int y) { return (x - 1) * m + y; }
matris Fe(matris x, int y) {
  if (y == 1) return x;
  matris h = Fe(x, y / 2);
  h = h * h;
  if (y & 1) h = h * x;
  return h;
}
void solve(int x) {
  matris now;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (cat[id(i, j)]) continue;
      for (int k = 0; k < 5; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx < 1 or ny < 1 or nx > n or ny > m or cat[id(nx, ny)]) continue;
        now.A[id(i, j)][id(nx, ny)] = 1;
      }
    }
  cur = cur * Fe(now, x);
}
int main() {
  int q, last = 1;
  scanf("%d%d%d", &n, &m, &q);
  cur.A[1][1] = 1;
  while (q--) {
    int tp, x, y, t;
    scanf("%d%d%d%d", &tp, &x, &y, &t);
    solve(t - last);
    last = t;
    if (tp == 1)
      printf("%d\n", cur.A[1][id(x, y)]);
    else
      cat[id(x, y)] = 3 - tp;
  }
  return 0;
}
