#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int n, m, q;
int mat[33][22][22];
int dp[22];
set<int> all;
int f(int i, int j) { return i * m + j; }
void mul(int res[22][22], int a[22][22], int b[22][22]) {
  for (int i = 0; i < n * m; ++i) {
    for (int j = 0; j < n * m; ++j) {
      res[i][j] = 0;
      for (int k = 0; k < n * m; ++k) {
        res[i][j] = (res[i][j] + 1LL * a[i][k] * b[k][j]) % MOD;
      }
    }
  }
}
void go(int step) {
  for (int mask = 0; step != 0; ++mask) {
    if (mask > 0) {
      mul(mat[mask], mat[mask - 1], mat[mask - 1]);
    }
    if ((step >> mask) & 1) {
      int ndp[22] = {};
      for (int i = 0; i < n * m; ++i) {
        for (int j = 0; j < n * m; ++j) {
          ndp[j] = (ndp[j] + 1LL * dp[i] * mat[mask][i][j]) % MOD;
        }
      }
      for (int i = 0; i < n * m; ++i) {
        dp[i] = ndp[i];
      }
      step ^= 1 << mask;
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int di = -1; di <= 1; ++di) {
        for (int dj = -1; dj <= 1; ++dj) {
          if (abs(di) + abs(dj) > 1) {
            continue;
          }
          int ni = i + di, nj = j + dj;
          if (ni < 0 || ni >= n || nj < 0 || nj >= m) {
            continue;
          }
          mat[0][f(i, j)][f(ni, nj)] = 1;
        }
      }
    }
  }
  int last = 1;
  dp[f(0, 0)] = 1;
  while (q-- > 0) {
    int type, x, y, t;
    scanf("%d%d%d%d", &type, &x, &y, &t);
    x--;
    y--;
    if (type == 2) {
      go(t - last);
      for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
          if (abs(dx) + abs(dy) > 1) {
            continue;
          }
          int nx = x + dx, ny = y + dy;
          if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
            continue;
          }
          mat[0][f(nx, ny)][f(x, y)] = 0;
          mat[0][f(x, y)][f(nx, ny)] = 0;
        }
      }
      all.insert(f(x, y));
      dp[f(x, y)] = 0;
    } else if (type == 3) {
      go(t - last);
      all.erase(f(x, y));
      for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
          if (abs(dx) + abs(dy) > 1) {
            continue;
          }
          int nx = x + dx, ny = y + dy;
          if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
            continue;
          }
          if (!all.count(f(nx, ny))) {
            mat[0][f(nx, ny)][f(x, y)] = 1;
            mat[0][f(x, y)][f(nx, ny)] = 1;
          }
        }
      }
    } else {
      go(t - last);
      printf("%d\n", dp[f(x, y)]);
    }
    last = t;
  }
  return 0;
}
