#include <bits/stdc++.h>
using namespace std;
int n, m;
inline bool valid(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return false;
  return true;
}
inline int f(int i, int j) {
  int x = i * (m) + j;
  return x;
}
void print(vector<vector<long long> > a) {
  cout << endl;
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < a[i].size(); j++) cout << a[i][j] << " ";
    cout << endl;
  }
}
inline vector<vector<long long> > iden(int n) {
  vector<vector<long long> > a;
  a.resize(n);
  for (int i = 0; i < n; i++) a[i].assign(n, 0);
  for (int i = 0; i < n; i++) a[i][i] = 1;
  return a;
}
inline vector<vector<long long> > iden2(int n) {
  vector<vector<long long> > a;
  a.resize(n);
  for (int i = 0; i < n; i++) a[i].assign(n, 0);
  for (int i = 0; i < n; i++) a[i][i] = 0;
  return a;
}
inline vector<vector<long long> > matrixmulti(vector<vector<long long> > m1,
                                              vector<vector<long long> > m2) {
  vector<vector<long long> > m3;
  int a = m1.size(), b = m1[0].size(), c = m2.size(), d = m2[0].size();
  if (b != c) cout << "CANNOT MULTIPLY" << endl;
  m3.resize(a);
  for (int i = 0; i < a; i++) m3[i].assign(d, 0);
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < d; j++) {
      m3[i][j] = 0;
      for (int k = 0; k < b; k++)
        m3[i][j] =
            (m3[i][j] + (m1[i][k] * 1ll * m2[k][j]) % (long long)(1e9 + 7)) %
            (long long)(1e9 + 7);
    }
  }
  return m3;
}
inline vector<vector<long long> > matrixpower(vector<vector<long long> > a,
                                              int n) {
  if (n == 0) return iden(a.size());
  vector<vector<long long> > res = iden(a.size());
  vector<vector<long long> > b = a;
  while (n) {
    if (n & 1) res = matrixmulti(res, b);
    b = matrixmulti(b, b);
    n >>= 1;
  }
  return res;
}
vector<vector<long long> > make(int k) {
  vector<vector<long long> > res;
  res.resize(k);
  for (int i = 0; i < k; i++) res[i].assign(k, 0);
  for (int i = 0; i < k; i++) {
    int a, b;
    if (m != 1)
      b = i % m;
    else
      b = 0;
    a = (i - b) / (m);
    res[i][i] = 1;
    if (valid(a + 1, b)) {
      res[i][f(a + 1, b)] = 1;
    }
    if (valid(a - 1, b)) {
      res[i][f(a - 1, b)] = 1;
    }
    if (valid(a, b + 1)) {
      res[i][f(a, b + 1)] = 1;
    }
    if (valid(a, b - 1)) {
      res[i][f(a, b - 1)] = 1;
    }
  }
  return res;
}
vector<vector<long long> > makebase(int k = 3) {
  vector<vector<long long> > res;
  res.resize(k);
  for (int i = 0; i < k; i++) {
    res[i].resize(1);
    res[i][0] = 0;
  }
  res[1][0] = 1;
  return res;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int k = m * n;
  int q;
  scanf("%d", &q);
  vector<vector<long long> > res = make(k);
  vector<vector<long long> > ans;
  ans.resize(1);
  ans[0].assign(k, 0);
  ans[0][0] = 1;
  int cur = 1;
  while (q--) {
    int tp;
    scanf("%d", &tp);
    int x, y, t;
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &t);
    x--;
    y--;
    if (tp == 1) {
      vector<vector<long long> > B = matrixpower(res, t - cur);
      ans = matrixmulti(ans, B);
      int num = (int)ans[0][f(x, y)];
      cur = t;
      printf("%d\n", num);
    } else if (tp == 2) {
      int num = f(x, y);
      int pw = t - cur;
      vector<vector<long long> > B = matrixpower(res, pw - 1);
      ans = matrixmulti(ans, B);
      for (int i = 0; i < k; i++) res[i][num] = 0;
      ans = matrixmulti(ans, res);
      cur = t;
    } else if (tp == 3) {
      int num = f(x, y);
      int pw = t - cur;
      vector<vector<long long> > B = matrixpower(res, pw);
      ans = matrixmulti(ans, B);
      res[num][num] = 1;
      int a = x, b = y;
      if (valid(a + 1, b)) res[f(a + 1, b)][num] = 1;
      if (valid(a - 1, b)) res[f(a - 1, b)][num] = 1;
      if (valid(a, b + 1)) res[f(a, b + 1)][num] = 1;
      if (valid(a, b - 1)) res[f(a, b - 1)][num] = 1;
      cur = t;
    }
  }
  return 0;
}
