Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.

After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.

The bookcase consists of n shelves, and each shelf has exactly m positions for books at it. Alina enumerates shelves by integers from 1 to n and positions at shelves — from 1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.

Alina wrote down q operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:

  * 1 i j — Place a book at position j at shelf i if there is no book at it.
  * 2 i j — Remove the book from position j at shelf i if there is a book at it.
  * 3 i — Invert book placing at shelf i. This means that from every position at shelf i which has a book at it, the book should be removed, and at every position at shelf i which has not book at it, a book should be placed.
  * 4 k — Return the books in the bookcase in a state they were after applying k-th operation. In particular, k = 0 means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.



After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?

Input

The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 103, 1 ≤ q ≤ 105) — the bookcase dimensions and the number of operations respectively.

The next q lines describes operations in chronological order — i-th of them describes i-th operation in one of the four formats described in the statement.

It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the number k corresponds to some operation before it or equals to 0.

Output

For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.

Examples

Input

2 3 3
1 1 1
3 2
4 0


Output

1
4
0


Input

4 2 6
3 2
2 2 2
3 3
3 2
2 2 2
3 2


Output

2
1
3
3
2
4


Input

2 2 2
3 2
2 2 1


Output

2
1

Note

<image>

This image illustrates the second sample case.
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, m, q, op[100010], X[100010], Y[100010], Head[100010], Next[100010],
    Go[100010], Ans[100010], Cnt = 0, nans = 0;
bool B[1010][1010];
inline void addedge(int x, int y) {
  Go[++Cnt] = y, Next[Cnt] = Head[x], Head[x] = Cnt;
}
void DFS(int x) {
  int b = 0;
  if (op[x] == 1 && B[X[x]][Y[x]] == 0) b = 1, B[X[x]][Y[x]] = 1, nans++;
  if (op[x] == 2 && B[X[x]][Y[x]] == 1) b = 1, B[X[x]][Y[x]] = 0, nans--;
  if (op[x] == 3) {
    b = 1;
    int s = X[x];
    for (int i = 1; i <= m; i++)
      if (B[s][i] == 0)
        B[s][i] = 1, nans++;
      else
        B[s][i] = 0, nans--;
  }
  Ans[x] = nans;
  for (int T = Head[x]; T; T = Next[T]) DFS(Go[T]);
  if (!b) return;
  if (op[x] == 1) B[X[x]][Y[x]] = 0, nans--;
  if (op[x] == 2) B[X[x]][Y[x]] = 1, nans++;
  if (op[x] == 3) {
    int s = X[x];
    for (int i = 1; i <= m; i++)
      if (B[s][i] == 0)
        B[s][i] = 1, nans++;
      else
        B[s][i] = 0, nans--;
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &op[i], &X[i]);
    if (op[i] == 1 || op[i] == 2) scanf("%d", &Y[i]);
    if (op[i] == 4)
      addedge(X[i], i);
    else
      addedge(i - 1, i);
  }
  for (int T = Head[0]; T; T = Next[T]) DFS(Go[T]);
  for (int i = 1; i <= q; i++) printf("%d\n", Ans[i]);
  return 0;
}
