Gosha's universe is a table consisting of n rows and m columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (r, c) to denote a cell located in the row r and column c.

Gosha is often invited somewhere. Every time he gets an invitation, he first calculates the number of ways to get to this place, and only then he goes. Gosha's house is located in the cell (1, 1).

At any moment of time, Gosha moves from the cell he is currently located in to a cell adjacent to it (two cells are adjacent if they share a common side). Of course, the movement is possible only if such a cell exists, i.e. Gosha will not go beyond the boundaries of the table. Thus, from the cell (r, c) he is able to make a move to one of the cells (r - 1, c), (r, c - 1), (r + 1, c), (r, c + 1). Also, Ghosha can skip a move and stay in the current cell (r, c).

Besides the love of strange calculations, Gosha is allergic to cats, so he never goes to the cell that has a cat in it. Gosha knows exactly where and when he will be invited and the schedule of cats travelling along the table. Formally, he has q records, the i-th of them has one of the following forms: 

  * 1, xi, yi, ti — Gosha is invited to come to cell (xi, yi) at the moment of time ti. It is guaranteed that there is no cat inside cell (xi, yi) at this moment of time. 
  * 2, xi, yi, ti — at the moment ti a cat appears in cell (xi, yi). It is guaranteed that no other cat is located in this cell (xi, yi) at that moment of time. 
  * 3, xi, yi, ti — at the moment ti a cat leaves cell (xi, yi). It is guaranteed that there is cat located in the cell (xi, yi). 



Gosha plans to accept only one invitation, but he has not yet decided, which particular one. In order to make this decision, he asks you to calculate for each of the invitations i the number of ways to get to the cell (xi, yi) at the moment ti. For every invitation, assume that Gosha he starts moving from cell (1, 1) at the moment 1.

Moving between two neighboring cells takes Gosha exactly one unit of tim. In particular, this means that Gosha can come into the cell only if a cat sitting in it leaves the moment when Gosha begins his movement from the neighboring cell, and if none of the cats comes to the cell at the time when Gosha is in it.

Two ways to go from cell (1, 1) to cell (x, y) at time t are considered distinct if for at least one moment of time from 1 to t Gosha's positions are distinct for the two ways at this moment. Note, that during this travel Gosha is allowed to visit both (1, 1) and (x, y) multiple times. Since the number of ways can be quite large, print it modulo 109 + 7.

Input

The first line of the input contains three positive integers n, m and q (1 ≤ n·m ≤ 20, 1 ≤ q ≤ 10 000) — the number of rows and columns in the table and the number of events respectively.

Next q lines describe the events, each description contains four integers tpi, xi, yi and ti (1 ≤ tp ≤ 3, 1 ≤ x ≤ n, 1 ≤ y ≤ m, 2 ≤ t ≤ 109) — the type of the event (1 if Gosha gets an invitation, 2 if a cat comes to the cell and 3 if a cat leaves the cell), the coordinates of the cell where the action takes place and the moment of time at which the action takes place respectively.

It is guaranteed that the queries are given in the chronological order, i.e. ti < ti + 1. 

Output

For each invitation i (that is, tpi = 1) calculate the number of ways to get to cell (xi, yi) at the moment of time ti. Respond to the invitations chronologically, that is, in the order they appear in the input.

Examples

Input

1 3 3
2 1 2 3
3 1 2 5
1 1 1 7


Output

5


Input

3 3 3
2 2 2 2
1 3 3 5
1 3 3 7


Output

2
42


Input

4 5 5
2 2 5 3
2 2 4 6
3 2 4 9
1 4 4 13
1 4 4 15


Output

490902
10598759

Note

Explanation of the first sample. Each picture specifies the number of ways to arrive at the cell at the appropriate time. (X stands for a cell blocked at this particular moment of time)

<image> Time moment 1.  <image> Time moment 2. <image> Time moment 3. <image> Time moment 4. <image> Time moment 5. <image> Time moment 6. <image> Time moment 7.
#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int n, m, q, last, vi[N][N];
int dx[5] = {0, -1, 1, 0, 0};
int dy[5] = {0, 0, 0, -1, 1};
inline void add(int &a, int b) {
  a = ((a + b >= 1000000007) ? a + b - 1000000007 : a + b);
}
inline void del(int &a, int b) {
  a = ((a - b < 0) ? a - b + 1000000007 : a - b);
}
inline void mul(int &a, int b) { a = 1ll * a * b % 1000000007; }
inline int id(int x, int y) { return (x - 1) * m + y; }
inline int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
struct matrix {
  int n, a[N][N];
  inline void clear() { memset(a, 0, sizeof(a)); }
  inline void init() {
    for (int i = 1; i <= n; i++) a[i][i] = 1;
  }
  inline void print() {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf("%d ", a[i][j]);
      printf("\n");
    }
  }
} f;
matrix tr;
matrix operator*(matrix a, matrix b) {
  matrix ans;
  ans.n = a.n;
  ans.clear();
  for (int i = 1; i <= a.n; i++) {
    for (int k = 1; k <= a.n; k++) {
      for (int j = 1; j <= a.n; j++)
        add(ans.a[i][j], 1ll * a.a[i][k] * b.a[k][j] % 1000000007);
    }
  }
  return ans;
}
matrix m_pow(matrix a, int b) {
  matrix ans;
  ans.n = a.n;
  ans.clear();
  ans.init();
  while (b) {
    if (b & 1) ans = ans * a;
    b >>= 1;
    a = a * a;
  }
  return ans;
}
inline void get() {
  tr.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (vi[i][j]) continue;
      tr.a[id(i, j)][id(i, j)] = 1;
      for (int k = 1; k <= 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x <= 0 || y <= 0 || x > n || y > m || vi[x][y]) continue;
        tr.a[id(i, j)][id(x, y)] = 1;
      }
    }
  }
}
signed main() {
  n = read();
  m = read();
  q = read();
  last = 1;
  f.n = tr.n = n * m;
  f.a[1][1] = 1;
  get();
  while (q--) {
    int op = read(), x = read(), y = read(), t = read();
    f = f * m_pow(tr, t - last);
    last = t;
    if (op == 2) vi[x][y] = 1;
    if (op == 3) vi[x][y] = 0;
    if (op == 1) printf("%d\n", f.a[1][id(x, y)]);
    get();
  }
}
