#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int Mat_SIZE = 21;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int szz;
struct Matrix {
  int mat[Mat_SIZE][Mat_SIZE];
  void init() {
    for (int i = 0; i < szz; i++)
      for (int j = 0; j < szz; j++) mat[i][j] = 0;
  }
  void init_base() {
    init();
    for (int i = 0; i < szz; i++) mat[i][i] = 1;
  }
  void display() {
    for (int i = 0; i < szz; i++) {
      for (int j = 0; j < szz; j++) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }
} base, A;
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  for (int i = 0; i < szz; i++)
    for (int j = 0; j < szz; j++) {
      c.mat[i][j] = 0;
      for (int k = 0; k < szz; k++)
        c.mat[i][j] =
            (c.mat[i][j] + (long long)a.mat[i][k] * b.mat[k][j] % MOD) % MOD;
    }
  return c;
}
Matrix operator^(Matrix a, int k) {
  Matrix ret;
  ret.init_base();
  while (k) {
    if (k & 1) ret = ret * a;
    a = a * a;
    k >>= 1;
  }
  return ret;
}
int n, m, q, ty, x, y, t;
int cat[Mat_SIZE][Mat_SIZE];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int id(int x, int y) { return x * m + y; }
bool ing(int x, int y) {
  if (x < 0 || x >= n) return false;
  if (y < 0 || y >= m) return false;
  return true;
}
void get_base() {
  base.init();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (!cat[i][j]) base.mat[id(i, j)][id(i, j)] = 1;
      for (int k = 0; k < 4; k++) {
        int nx = i + dx[k];
        int ny = j + dy[k];
        if (!ing(nx, ny) || cat[nx][ny]) continue;
        base.mat[id(i, j)][id(nx, ny)] = 1;
      }
    }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  szz = n * m;
  get_base();
  A.init();
  A.mat[0][0] = 1;
  int curx = 0, cury = 0, curt = 1;
  for (int i = 0; i < q; i++) {
    scanf("%d%d%d%d", &ty, &x, &y, &t);
    x--;
    y--;
    if (ty == 1) {
      A = A * (base ^ (t - curt));
      printf("%d\n", A.mat[0][id(x, y)]);
    } else if (ty == 2) {
      A = A * (base ^ (t - curt - 1));
      cat[x][y] = 1;
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (!ing(nx, ny)) continue;
        base.mat[id(nx, ny)][id(x, y)] = 0;
        base.mat[id(x, y)][id(nx, ny)] = cat[nx][ny] ^ 1;
      }
      base.mat[id(x, y)][id(x, y)] = 0;
      A = A * base;
    } else {
      A = A * (base ^ (t - curt));
      cat[x][y] = 0;
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (!ing(nx, ny)) continue;
        base.mat[id(nx, ny)][id(x, y)] = 1;
        base.mat[id(x, y)][id(nx, ny)] = cat[nx][ny] ^ 1;
      }
      base.mat[id(x, y)][id(x, y)] = 1;
    }
    curx = x;
    cury = y;
    curt = t;
  }
  return 0;
}
