#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
template <typename T>
struct matrix : vector<vector<T>> {
  int n, m;
  void print() {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << (*this)[i][j] << " ";
      cout << '\n';
    }
  }
  matrix(int n_, int m_, bool ident = false)
      : vector<vector<T>>(n_, vector<T>(m_, 0)), n(n_), m(m_) {
    if (ident) {
      assert(n == m);
      for (int i = 0; i < n; i++) (*this)[i][i] = 1;
    }
  }
  matrix(const vector<vector<T>>& c)
      : vector<vector<T>>(c), n(c.size()), m(c[0].size()) {}
  matrix(const initializer_list<initializer_list<T>>& c) {
    vector<vector<T>> val;
    for (auto& i : c) val.push_back(i);
    *this = matrix(val);
  }
  matrix<T> operator*(matrix<T>& r) {
    assert(m == r.n);
    matrix<T> M(n, r.m);
    for (int i = 0; i < n; i++)
      for (int k = 0; k < m; k++)
        for (int j = 0; j < r.m; j++) {
          T add = (*this)[i][k] * r[k][j];
          M[i][j] += add;
        }
    return M;
  }
  matrix<T> operator^(long long e) {
    matrix<T> M(n, n, true), at = *this;
    while (e) {
      if (e & 1) M = M * at;
      e >>= 1;
      at = at * at;
    }
    return M;
  }
};
int n, m;
int pos(int a, int b) { return b + a * m; }
pair<int, int> cord(int x) { return {x / m, x % n}; }
vector<pair<int, int>> dx = {{0, 0}, {0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> n >> m >> q;
  vector<tuple<int, int, int, int, int>> ev(q);
  int cnt = 0;
  for (auto& [t, tp, x, y, id] : ev) {
    cin >> tp >> x >> y >> t;
    x--, y--;
    if (tp == 1) id = cnt++;
  }
  matrix<long long> A(n * m, n * m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      for (auto [x, y] : dx) {
        x += i, y += j;
        if (x >= 0 and x < n and y >= 0 and y < m) A[pos(i, j)][pos(x, y)] = 1;
      }
    }
  int t_at = 1;
  vector<int> cats(n * m);
  matrix<long long> at(n * m, n * m, 1);
  vector<int> ans(cnt);
  for (auto [t, tp, x, y, id] : ev) {
    if (t > t_at) {
      if (tp == 1 or tp == 2 or tp == 3) {
        matrix<long long> A2 = A ^ (t - t_at);
        at = at * A2;
        t_at = t;
      } else {
        matrix<long long> A2 = A ^ (t - 1 - t_at);
        at = at * A2;
        t_at = t - 1;
      }
    }
    if (tp == 1) {
      ans[id] = at[pos(0, 0)][pos(x, y)];
    } else if (tp == 2) {
      cats[pos(x, y)] = 1;
      for (auto [xx, yy] : dx) {
        xx += x, yy += y;
        if (xx >= 0 and xx < n and yy >= 0 and yy < m)
          A[pos(x, y)][pos(xx, yy)] = 0, A[pos(xx, yy)][pos(x, y)] = 0;
      }
    } else {
      cats[pos(x, y)] = 0;
      for (auto [xx, yy] : dx) {
        xx += x, yy += y;
        if (xx >= 0 and xx < n and yy >= 0 and yy < m and !cats[pos(xx, yy)])
          A[pos(x, y)][pos(xx, yy)] = 1, A[pos(xx, yy)][pos(x, y)] = 1;
      }
    }
  }
  for (auto u : ans) cout << u << '\n';
  exit(0);
}
