#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
int n, m, q;
int check(int x, int y) { return (0 < x) && (x <= n) && (0 < y) && (y <= m); }
int id(int x, int y) { return (x - 1) * m + y - 1; }
int add_mod(long long a, long long b) { return (a + b) % MOD; }
int mul_mod(long long a, long long b) { return a * b % MOD; }
struct Matrix {
  int r, c;
  vector<vector<int> > a;
  Matrix(int r, int c, int d = 0) : r(r), c(c) {
    a.assign(r, vector<int>(c, 0));
    for (int i = 0; (i < r) && (i < c); i++) a[i][i] = d;
  }
  vector<int>& operator[](int i) { return a[i]; }
  const vector<int>& operator[](int i) const { return a[i]; }
  Matrix operator*(const Matrix& B) const {
    Matrix ans(r, B.c);
    for (int i = 0; i < r; i++)
      for (int j = 0; j < B.c; j++)
        for (int k = 0; k < c; k++)
          ans[i][j] = add_mod(ans[i][j], mul_mod(a[i][k], B[k][j]));
    return ans;
  }
  Matrix pow(int p) const {
    Matrix ans(r, c, 1), a(*this);
    for (; p > 0; p >>= 1) {
      if (p & 1) ans = ans * a;
      a = a * a;
    }
    return ans;
  }
  void set(int x, int y) {
    a[id(x, y)][id(x, y)] = 1;
    for (int k = 0; k < 4; k++)
      if (check(x + dx[k], y + dy[k]))
        a[id(x, y)][id(x + dx[k], y + dy[k])] = 1;
  }
  void clear(int x, int y) {
    for (int i = 0; i < c; i++) a[id(x, y)][i] = 0;
  }
};
int main() {
  scanf("%d%d%d", &n, &m, &q);
  Matrix f(n * m, n * m);
  for (int x = 1; x <= n; x++)
    for (int y = 1; y <= m; y++) f.set(x, y);
  int cur = 1;
  Matrix a(n * m, 1);
  a[0][0] = 1;
  while (q--) {
    int k, x, y, t;
    scanf("%d%d%d%d", &k, &x, &y, &t);
    t -= cur;
    cur += t;
    if (k == 1) {
      a = f.pow(t) * a;
      printf("%d\n", a[id(x, y)][0]);
    } else if (k == 2) {
      a = f.pow(t) * a;
      f.clear(x, y);
      a[id(x, y)][0] = 0;
    } else {
      a = f.pow(t) * a;
      f.set(x, y);
    }
  }
}
