Attacked squares

After each rook relocation on a large board, count squares where the xor of powers of rooks in the same row or column is nonzero.

Medium7Bit manipulationHash mapMathNo attempts yetTime limit2sMemory limit64 MB

Problem

Mirko likes chess and programming. Ordinary chess bored him quickly, so he came up with a game that uses only rooks.

He found a chessboard with NN rows and NN columns and placed KK rooks on it.

The rules are:

  1. Every rook has a power, given as one integer.
  2. A rook sees every square of its own row and its own column, except the square it stands on.
  3. A square is attacked if the binary XOR of the powers of all rooks that see it is greater than 00.

A square that holds a rook can be attacked as well.

Mirko starts from the initial layout and makes PP moves. After each move, find how many squares are attacked.

A rook can be moved to any free square of the board. The move is not restricted to its own row or column.

Input

The first line contains the integers NN, KK, PP (1N1091 \le N \le 10^9, 1K1051 \le K \le 10^5, 1P1051 \le P \le 10^5).

Each of the next KK lines contains three integers RR, CC, XX (1R,CN1 \le R, C \le N, 1X1091 \le X \le 10^9), meaning that a rook of power XX starts on square (R,C)(R, C).

Each of the next PP lines contains four integers R1R_1, C1C_1, R2R_2, C2C_2 (1R1,C1,R2,C2N1 \le R_1, C_1, R_2, C_2 \le N), meaning that a rook moved from square (R1,C1)(R_1, C_1) to square (R2,C2)(R_2, C_2).

No two rooks stand on the same square at any point.

Output

Print PP lines. Line kk contains the number of attacked squares after the kkth move.

Hint

An explanation of the first example. After the first move every square of the board is attacked. Square (1,1)(1, 1), for instance, is seen by one rook only, so the XOR for that square is 11. After the second move no square is attacked. Square (1,1)(1, 1) is seen by both rooks, and the XOR of their powers is 00.