#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = 25, mod = (int)1e9 + 7;
unordered_map<int, long long> dp[maxn][maxn][maxn][maxn];
bool us[maxn][maxn];
int n, m;
void clear() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int t = 1; t <= n; t++) {
        for (int k = 1; k <= m; k++) {
          dp[i][j][t][k].clear();
        }
      }
    }
  }
}
long long go(int x1, int y1, int x2, int y2, int t) {
  if (us[x1][y1] || us[x2][y2]) {
    dp[x1][y1][x2][y2][t] = 0;
  }
  if (!dp[x1][y1][x2][y2].count(t)) {
    if (t == 0) {
      if (x1 == x2 && y1 == y2) {
        dp[x1][y1][x2][y2][t] = 1;
      } else {
        dp[x1][y1][x2][y2][t] = 0;
      }
    } else if (t == 1) {
      if (abs(x1 - x2) + abs(y1 - y2) <= 1) {
        dp[x1][y1][x2][y2][t] = 1;
      } else {
        dp[x1][y1][x2][y2][t] = 0;
      }
    } else {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if (!us[i][j]) {
            dp[x1][y1][x2][y2][t] +=
                go(x1, y1, i, j, t / 2) * go(i, j, x2, y2, t - t / 2);
            dp[x1][y1][x2][y2][t] %= mod;
          }
        }
      }
    }
  }
  return dp[x1][y1][x2][y2][t];
}
long long cnt[maxn][maxn];
long long ncnt[maxn][maxn];
int main() {
  int q;
  scanf("%d %d %d", &n, &m, &q);
  int last = 1;
  cnt[1][1] = 1;
  while (q--) {
    int tp;
    scanf("%d", &tp);
    int x, y, tt;
    scanf("%d %d %d", &x, &y, &tt);
    clear();
    memset(ncnt, 0, sizeof ncnt);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int t = 1; t <= n; t++) {
          for (int k = 1; k <= m; k++) {
            ncnt[i][j] += cnt[t][k] * go(t, k, i, j, tt - last);
            ncnt[i][j] %= mod;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cnt[i][j] = ncnt[i][j];
      }
    }
    if (tp == 2) {
      cnt[x][y] = 0;
      us[x][y] = true;
    } else if (tp == 3) {
      us[x][y] = false;
    } else {
      printf("%I64d\n", cnt[x][y]);
    }
    last = tt;
  }
  return 0;
}
