#include <bits/stdc++.h>
using namespace std;
constexpr long long int asdfa = 1000000007;
array<array<long long int, 20>, 20> id;
array<array<long long int, 20>, 20> operator*(
    array<array<long long int, 20>, 20> a,
    array<array<long long int, 20>, 20> b) {
  array<array<long long int, 20>, 20> ret;
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      ret[i][j] = 0;
      for (int k = 0; k < 20; ++k) {
        ret[i][j] += a[i][k] * b[k][j];
        ret[i][j] %= asdfa;
      }
    }
  }
  return ret;
}
array<array<long long int, 20>, 20> mpow(array<array<long long int, 20>, 20> x,
                                         int e) {
  if (e == 0) return id;
  array<array<long long int, 20>, 20> s = mpow(x, e / 2);
  s = s * s;
  if (e & 1) s = s * x;
  return s;
}
int n, m, q;
bool cat[20];
array<array<long long int, 20>, 20> mat;
int di[5] = {-1, 0, 1, 0, 0};
int dj[5] = {0, -1, 0, 1, 0};
void recomp() {
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      mat[i][j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (cat[m * i + j]) continue;
      for (int d = 0; d < 5; ++d) {
        int i2 = i + di[d];
        int j2 = j + dj[d];
        if (i2 == -1 || i2 == n || j2 == -1 || j2 == m) continue;
        mat[m * i2 + j2][m * i + j] = 1;
      }
    }
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> q;
  array<array<long long int, 20>, 20> xd;
  for (int i = 0; i < 20; ++i) {
    for (int j = 0; j < 20; ++j) {
      id[i][j] = (i == j ? 1 : 0);
      xd[i][j] = ((i == j && j == 0) ? 1 : 0);
    }
  }
  int oldt = 1;
  recomp();
  for (int i = 0; i < q; ++i) {
    int tp, x, y, t;
    cin >> tp >> x >> y >> t;
    --x;
    --y;
    xd = mpow(mat, t - oldt) * xd;
    for (int i = 0; i < n * m; ++i) {
      if (cat[i]) {
        for (int j = 0; j < n * m; ++j) {
          xd[i][j] = 0;
        }
      }
    }
    if (tp == 1) {
      cout << xd[m * x + y][0] << '\n';
    } else if (tp == 2) {
      cat[m * x + y] = true;
      recomp();
    } else {
      cat[m * x + y] = false;
      recomp();
    }
    oldt = t;
  }
  return 0;
}
