#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<vector<long long>> a;
vector<vector<long long>> b;
vector<vector<long long>> c;
void multi() {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++) {
        c[i][j] = (c[i][j] + a[i][k] * b[k][j] % mod) % mod;
      }
    }
  }
}
void print_mat(vector<vector<long long>> a) {
  cout << endl;
  for (vector<long long> b : a) {
    for (int c : b) cout << c << " ";
    cout << endl;
  }
  cout << endl;
}
vector<vector<long long>> d;
void pwr(int p) {
  while (p) {
    if (p % 2) {
      a = d;
      multi();
      d = c;
    }
    p /= 2;
    a = b;
    multi();
    b = c;
  }
}
vector<vector<long long>> adj;
vector<vector<long long>> ans;
vector<vector<long long>> I;
int n, m;
void change_adj(int i, int j, int val) {
  int ind = i * m + j;
  int ind1 = -1, ind2 = -1, ind3 = -1, ind4 = -1;
  if (i > 0) {
    ind1 = (i - 1) * m + j;
    adj[ind1][ind] += val;
  }
  if (i < n - 1) {
    ind2 = (i + 1) * m + j;
    adj[ind2][ind] += val;
  }
  if (j > 0) {
    ind3 = i * m + (j - 1);
    adj[ind3][ind] += val;
  }
  if (j < m - 1) {
    ind4 = i * m + (j + 1);
    adj[ind4][ind] += val;
  }
  adj[ind][ind] += val;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q;
  cin >> n >> m >> q;
  adj = vector<vector<long long>>(n * m, vector<long long>(n * m, 0));
  I = vector<vector<long long>>(n * m, vector<long long>(n * m, 0));
  c = vector<vector<long long>>(n * m, vector<long long>(n * m, 0));
  ans = vector<vector<long long>>(n * m, vector<long long>(n * m, 0));
  ans[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ind = i * m + j;
      int ind1 = -1, ind2 = -1, ind3 = -1, ind4 = -1;
      if (i > 0) {
        ind1 = (i - 1) * m + j;
        adj[ind][ind1] = 1;
      }
      if (i < n - 1) {
        ind2 = (i + 1) * m + j;
        adj[ind][ind2] = 1;
      }
      if (j > 0) {
        ind3 = i * m + (j - 1);
        adj[ind][ind3] = 1;
      }
      if (j < m - 1) {
        ind4 = i * m + (j + 1);
        adj[ind][ind4] = 1;
      }
      adj[ind][ind] = 1;
    }
  }
  for (int i = 0; i < n * m; i++) {
    I[i][i] = 1;
  }
  int cur_time = 1;
  for (int i = 0; i < q; i++) {
    int tp, x, y, t;
    cin >> tp >> x >> y >> t;
    x--;
    y--;
    int delta = t - cur_time;
    cur_time = t;
    d = I;
    b = adj;
    if (tp == 1) {
      pwr(delta);
    } else if (tp == 2) {
      pwr(delta - 1);
      change_adj(x, y, -1);
      a = d;
      b = adj;
      multi();
      d = c;
    } else {
      pwr(delta);
      change_adj(x, y, 1);
    }
    a = ans;
    b = d;
    multi();
    ans = c;
    if (tp == 1) cout << ans[0][x * m + y] << "\n";
  }
  return 0;
}
