#include <bits/stdc++.h>
using namespace std;
void prepare() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
long long mod = 1e9 + 7;
vector<vector<long long> > a;
long long binmno(long long a, long long b) {
  long long ans = 0;
  while (a) {
    if (a & 1) {
      ans = (ans + b % mod) % mod;
      a--;
    } else {
      b = (b + b) % mod;
      a /= 2;
    }
  }
  return ans % mod;
}
vector<vector<long long> > operator*(vector<vector<long long> > a,
                                     vector<vector<long long> > b) {
  vector<vector<long long> > ans((long long)a.size(),
                                 vector<long long>(a.size(), 0));
  for (long long i = 0; i < a.size(); i++) {
    for (long long j = 0; j < a.size(); j++) {
      for (long long q = 0; q < a.size(); q++) {
        ans[i][j] += binmno(a[i][q], b[q][j]);
        ans[i][j] %= mod;
      }
    }
  }
  return ans;
}
vector<vector<long long> > binpow(long long k) {
  vector<vector<long long> > ans(a.size(), vector<long long>(a.size(), 0));
  for (int i = 0; i < a.size(); i++) ans[i][i] = 1;
  while (k) {
    if (k % 2 == 0) {
      k /= 2;
      a = a * a;
    } else {
      k--;
      ans = a * ans;
    }
  }
  return ans;
}
vector<long long> operator*(vector<vector<long long> > a, vector<long long> b) {
  vector<long long> ans(b.size());
  for (int i = 0; i < b.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      ans[i] += binmno(a[i][j], b[j]);
      ans[i] %= mod;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  long long n, m, q;
  cin >> n >> m >> q;
  a.assign(n * m, vector<long long>(n * m));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      a[i * n + j][i * n + j] = 1;
      if (j != 0) {
        a[i * n + j][i * n + j - 1] = 1;
      }
      if (j != n - 1) {
        a[i * n + j][i * n + j + 1] = 1;
      }
      if (i != 0) {
        a[(i - 1) * n + j][i * n + j] = 1;
      }
      if (i != m - 1) {
        a[(i + 1) * n + j][i * n + j] = 1;
      }
    }
  }
  vector<vector<long long> > lasta = a;
  vector<vector<long long> > a1 = a;
  vector<long long> pl(n * m, 0);
  pl[0] = 1;
  int lastt = 1;
  for (int i = 0; i < q; i++) {
    int t1, x, y, t;
    cin >> t1 >> x >> y >> t;
    a = a1;
    x--;
    y--;
    a = binpow(t - lastt);
    lastt = t;
    pl = a * pl;
    int place = y * n + x;
    if (t1 == 1) {
      cout << pl[place] << endl;
      continue;
    }
    if (t1 == 2) {
      pl[place] = 0;
      for (int i = 0; i < n * m; i++) {
        a1[place][i] = 0;
      }
    }
    if (t1 == 3) {
      for (int i = 0; i < n * m; i++) {
        a1[place][i] = lasta[place][i];
      }
    }
  }
  return 0;
}
