#include <bits/stdc++.h>
using namespace std;
int dr[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
int const MAX = 100 + 7;
int const MOD = 1e9 + 7;
class matrix {
 public:
  vector<vector<long long>> mat;
  matrix(long long n, long long m, long long num = -1) {
    mat.resize(n);
    if (num == -1)
      for (int i = 0; i < n; ++i) {
        mat[i].resize(m, 0);
        mat[i][i] = 1;
      }
    else
      for (int i = 0; i < n; ++i) mat[i].resize(m, num);
  }
  static vector<vector<long long>> multi_matrix(vector<vector<long long>> a,
                                                vector<vector<long long>> b) {
    matrix c(a.size(), b[0].size(), 0);
    for (int i = 0; i < a.size(); ++i)
      for (int j = 0; j < b[0].size(); ++j) {
        for (int k = 0; k < b.size(); ++k)
          c.mat[i][j] += (a[i][k] * b[k][j]) % MOD, c.mat[i][j] %= MOD;
      }
    return c.mat;
  }
  static vector<vector<long long>> matrix_power(vector<vector<long long>> a,
                                                long long k) {
    if (k == 0) {
      matrix c(a.size(), a.size());
      return c.mat;
    }
    if (k % 2 == 1) return multi_matrix(a, matrix_power(a, k - 1));
    return matrix_power(multi_matrix(a, a), k / 2);
  }
};
int n, m, q, cat[22][22];
vector<vector<long long>> bulid() {
  matrix G(n * m, n * m, 0);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (!cat[i][j]) {
        G.mat[i * m + j][i * m + j] = 1;
        for (int k = 0; k < 4; ++k)
          if (i + dr[k] != -1 && j + dc[k] != -1 && i + dr[k] < n &&
              j + dc[k] < m)
            if (!cat[i + dr[k]][j + dc[k]])
              G.mat[i * m + j][(i + dr[k]) * m + j + dc[k]] = 1;
      }
  return G.mat;
}
int main() {
  cin >> n >> m >> q;
  matrix G(n * m, n * m, 0), cur(n * m, n * m);
  int last_time = 1;
  for (int i = 0; i < q; ++i) {
    int tp, x, y, t;
    cin >> tp >> x >> y >> t;
    x--, y--;
    G.mat = bulid();
    cur.mat = matrix::multi_matrix(cur.mat,
                                   matrix::matrix_power(G.mat, t - last_time));
    if (tp == 1) {
      cout << cur.mat[0][x * m + y] % MOD << "\n";
    } else
      cat[x][y] ^= 1;
    last_time = t;
  }
}
