#include <bits/stdc++.h>
using namespace std;
int n, m, q;
long long ways[2][20][20] = {0};
bool cats[20][20] = {0};
long long moves[32][20][20] = {0};
void init() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          moves[0][m * i + j][m * k + l] =
              abs(k - i) + abs(l - j) <= 1 && !cats[k][l];
        }
      }
    }
  }
}
void mult(long long m1[20][20], long long m2[20][20], long long r[20][20],
          bool lazy) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < n; k++)
        for (int l = 0; l < m; l++) r[m * i + j][m * k + l] = 0;
  if (!lazy) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < n; k++) {
          for (int l = 0; l < m; l++) {
            for (int o = 0; o < n; o++) {
              for (int p = 0; p < m; p++) {
                r[m * i + j][m * o + p] =
                    (((r[m * i + j][m * o + p]) +
                      (((m1[m * i + j][m * k + l]) *
                        (m2[m * k + l][m * o + p]) % 1000000007))) %
                     1000000007);
              }
            }
          }
        }
      }
    }
  } else {
    for (int k = 0; k < n; k++) {
      for (int l = 0; l < m; l++) {
        for (int o = 0; o < n; o++) {
          for (int p = 0; p < m; p++) {
            r[0][m * o + p] = (((r[0][m * o + p]) +
                                (((m1[0][m * k + l]) *
                                  (m2[m * k + l][m * o + p]) % 1000000007))) %
                               1000000007);
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  init();
  ways[0][0][0] = 1;
  bool par = 0;
  int start = 1;
  for (int i = 0; i < q; i++) {
    int ty, x, y, t;
    scanf("%d %d %d %d", &ty, &x, &y, &t);
    x--;
    y--;
    int ahead = t - start;
    start = t;
    for (int j = 0; (ahead >> j) != 0; j++) {
      if (j >= 1) mult(moves[j - 1], moves[j - 1], moves[j], 0);
      if ((ahead >> j) & 1) {
        mult(ways[par], moves[j], ways[!par], 1);
        par = !par;
      }
    }
    if (ty == 1) {
      long long sum = 0;
      cout << ways[par][0][m * x + y] << '\n';
    } else if (ty == 2) {
      cats[x][y] = 1;
      init();
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) ways[par][m * i + j][m * x + y] = 0;
      }
    } else {
      cats[x][y] = 0;
      init();
    }
  }
}
