Preparando MOJI
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:
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?
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.
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.
2 3 3
1 1 1
3 2
4 0
1
4
0
4 2 6
3 2
2 2 2
3 3
3 2
2 2 2
3 2
2
1
3
3
2
4
2 2 2
3 2
2 2 1
2
1
This image illustrates the second sample case.