#include <bits/stdc++.h>
using namespace std;
constexpr int LIMIT = int(1e9 + 7);
struct matrix {
  int n;
  int m;
  vector<int> d;
  matrix(int n_, int m_) : n(n_), m(m_), d(n_ * m_) {}
  matrix(int n_, int m_, const vector<int>& d_) : n(n_), m(m_), d(d_) {}
  matrix(matrix&& o) : n(o.n), m(o.m), d(move(o.d)) {}
  matrix& operator=(matrix&& o) {
    n = o.n;
    m = o.m;
    d = move(o.d);
    return *this;
  }
  matrix copy() const { return matrix(n, m, d); }
  inline int& val(int i, int j) { return d[i * m + j]; }
  inline int val(int i, int j) const { return d[i * m + j]; }
  matrix operator*(const matrix& rh) const {
    int K = this->m;
    matrix res(this->n, rh.m);
    for (int i = 0; i < res.n; i++)
      for (int j = 0; j < res.m; j++)
        for (int k = 0; k < K; k++) {
          res.val(i, j) =
              (res.val(i, j) + (long long)(this->val(i, k)) * rh.val(k, j)) %
              LIMIT;
        }
    return move(res);
  }
};
matrix pow(const matrix& m, int p) {
  if (p < 2) {
    return m.copy();
  }
  matrix res = pow(m, p / 2);
  res = res * res;
  if (p % 2) res = res * m;
  return res;
}
void flipTransVal(matrix& trans, int n, int m, int i, bool force) {
  int val = (trans.val(i, i) + 1) % 2;
  trans.val(i, i) = val;
  auto d = div(i, m);
  int row = d.quot;
  int col = d.rem;
  vector<int> neib;
  neib.reserve(4);
  if (row - 1 >= 0) neib.push_back(i - m);
  if (row + 1 < n) neib.push_back(i + m);
  if (col - 1 >= 0) neib.push_back(i - 1);
  if (col + 1 < m) neib.push_back(i + 1);
  for (auto j : neib) {
    if (force || trans.val(j, j)) {
      trans.val(i, j) = val;
      trans.val(j, i) = val;
    }
  }
}
int main(int, char**) {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  int S = n * m;
  matrix state(1, S);
  matrix trans(S, S);
  state.d[0] = 1;
  for (int i = 0; i < S; i++) {
    flipTransVal(trans, n, m, i, true);
  }
  int t_prev = 1;
  while (q--) {
    int tp, x, y, t;
    scanf("%d%d%d%d", &tp, &x, &y, &t);
    int dt = t - t_prev;
    x -= 1;
    y -= 1;
    if (dt == 1)
      state = state * trans;
    else
      state = state * pow(trans, dt);
    int i = x * m + y;
    if (tp == 1) {
      printf("%d\n", state.d[i]);
    } else {
      flipTransVal(trans, n, m, i, false);
      state.d[i] = 0;
    }
    t_prev = t;
  }
  return 0;
}
