Artwork

Paint horizontal and vertical black strokes on a grid one at a time, and after each stroke report the number of white connected regions.

Hard8Union-findImplementationGraphSimulationNo attempts yetTime limit4sMemory limit512 MB

Problem

The template for an artwork is a white grid of n×mn \times m squares. The artwork is finished by painting qq horizontal or vertical black strokes on the grid.

A stroke starts at square (x1,y1)(x_1, y_1) and ends at square (x2,y2)(x_2, y_2), where x1=x2x_1 = x_2 or y1=y2y_1 = y_2. It turns every square (x,y)(x, y) with x1xx2x_1 \le x \le x_2 and y1yy2y_1 \le y \le y_2 black. Here xx is the row index and yy is the column index.

The beauty of an artwork is the number of regions in the grid. A region consists of one or more white squares, and any two squares of the same region are connected by a path of white squares that moves up, down, left, or right. Diagonal moves are not allowed. Before any stroke is painted, the beauty is 1.

Compute the beauty of the artwork after each stroke.

The figure below shows how the beauty changes while the strokes of the example are painted.


Figure 1: the example, stroke by stroke.

Input

The first line contains the integers nn, mm, and qq (1n,m10001 \le n, m \le 1000, 1q1041 \le q \le 10^4).

Each of the next qq lines describes one stroke with the integers x1x_1, y1y_1, x2x_2, and y2y_2 (1x1x2n1 \le x_1 \le x_2 \le n, 1y1y2m1 \le y_1 \le y_2 \le m). Every stroke satisfies x1=x2x_1 = x_2 or y1=y2y_1 = y_2, and both conditions can hold at the same time. The strokes are painted in the given order.

Output

For each of the qq strokes, print one line with the beauty of the artwork after that stroke.