#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
const int M = 25;
int tot;
struct Mat {
  int v[M][M];
  void clear() {
    for (int i = 0; i < M; ++i) {
      for (int j = 0; j < M; ++j) v[i][j] = 0;
    }
  }
  Mat(int x = 1) {
    clear();
    if (x = 1) {
      for (int i = 0; i < tot; ++i) v[i][i] = 1;
    }
  }
  void operator*=(Mat b) {
    Mat a = *this;
    clear();
    for (int i = 0; i < tot; ++i) {
      for (int j = 0; j < tot; ++j) {
        for (int k = 0; k < tot; ++k) {
          v[i][j] = (v[i][j] + 1LL * a.v[i][k] * b.v[k][j] % P) % P;
        }
      }
    }
  }
};
int n, m, q;
int ID[M][M];
int ans[M];
Mat B(0);
void Add(int x, int y) {
  B.v[ID[x][y]][ID[x][y]] ^= 1;
  if (x >= 1) B.v[ID[x - 1][y]][ID[x][y]] ^= 1;
  if (x < n - 1) B.v[ID[x + 1][y]][ID[x][y]] ^= 1;
  if (y >= 1) B.v[ID[x][y - 1]][ID[x][y]] ^= 1;
  if (y < m - 1) B.v[ID[x][y + 1]][ID[x][y]] ^= 1;
}
void calc(int t) {
  Mat res;
  Mat x = B;
  while (t) {
    if (t & 1) res *= x;
    x *= x, t >>= 1;
  }
  int tmp[M];
  for (int i = 0; i < tot; ++i) tmp[i] = ans[i], ans[i] = 0;
  for (int i = 0; i < tot; ++i) {
    for (int j = 0; j < tot; ++j) {
      ans[j] = (ans[j] + 1LL * tmp[i] * res.v[i][j] % P) % P;
    }
  }
}
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) ID[i][j] = tot++;
  }
  int las = 1;
  ans[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) Add(i, j);
  }
  for (int i = 0; i < q; ++i) {
    int k, x, y, t;
    cin >> k >> x >> y >> t;
    x--, y--;
    if (k == 1) {
      calc(t - las);
      cout << ans[ID[x][y]] << endl;
    } else if (k == 2) {
      calc(t - las - 1);
      Add(x, y);
      calc(1);
    } else {
      calc(t - las);
      Add(x, y);
    }
    las = t;
  }
}
