This page is still under construction.

Parts of this page are still being built. What you see may change.

Turtles in the Pond

Time limit2sMemory limit512 MB

Summary
Given a growing connected set of grid cells, after each insertion decide whether every pair can be joined by a path that uses only two fixed directions of movement.
Level

Hard8 of 10

Topics
Graph, Union-find, Implementation, Math
Solved
No attempts yet

Problem

The pond of Tortilla the turtle has changed a lot since Buratino's last visit. It is now a rectangular grid of ww columns and hh rows, with water lilies in some of its cells. On these lilies, on sunny days, numerous children, grandchildren, and great-grandchildren of Tortilla bask.

The pond contains a set of nn connected lilies. A set of lilies is connected if from any lily one can reach any other by moving between lilies that share a side.

Turtles love visiting each other. When one turtle decides to pay a visit to another, it builds some route that passes through lilies sharing a side and connects its lily to the lily of its acquaintance. However, the sedentary lifestyle of turtles imposes serious constraints on the possible routes: before starting to move, a turtle chooses some two of the four possible directions of movement (up, down, left, right) and then can step from lily to lily only in one of these two directions. For example, in the figure below, the turtle on lily A, wishing to visit the turtle on lily B, needs to choose the directions up and left in order to be able to lay out a route. On the other hand, the turtle on lily C cannot reach lily A, since any path connecting their lilies requires moving in at least three directions.

Turtles consider that the lilies in the pond are convenient for turtles if a turtle can get from any lily to any other using only two directions of movement. For example, the lilies in the pond in the figure above are inconvenient, since from the lily marked C one cannot reach the lily marked A. If, however, one adds to the existing lilies a lily in the cell marked with a star, then the lilies in the pond become convenient for turtles.

As a result of a family council, Tortilla decided to successively add qq new lilies to the nn existing ones.

Your task is to determine, before the additions and after each addition, whether the set of lilies is convenient for turtles. Tortilla guarantees that after each successive addition the set of lilies remains connected.

Input

The first line contains two integers hh, ww, the number of rows and columns in the grid that is the pond (1≤h,w≤100 0001 \leq h, w \leq 100\,000).

The next line contains an integer nn, the number of lilies in the pond initially (1≤n≤100 0001 \leq n \leq 100\,000).

The following nn lines contain two integers each, ri,cir_i, c_i: for each lily, the row and column numbers at whose intersection it is located (1≤ri≤h1 \leq r_i \leq h, 1≤ci≤w1 \leq c_i \leq w).

The next line contains an integer qq, the number of lilies Tortilla is going to add (0≤q≤100 0000 \leq q \leq 100\,000).

The following qq lines contain, in the same format, pairs of integers nri,ncinr_i, nc_i, denoting the row number and column number of the cell with the next added lily (1≤nri≤h1 \leq nr_i \leq h, 1≤nci≤w1 \leq nc_i \leq w).

It is guaranteed that no two lilies in the input coincide. It is guaranteed that initially and after each addition the set of lilies is connected.

Output

Output q+1q + 1 lines, each of which is either the word YES or the word NO, depending on whether at the corresponding moment the system of lilies is convenient for turtles or not. The first line must contain the answer for the initial arrangement of lilies, and each subsequent line must contain the answer after the next added lily.

Examples2

  1. Example 1

    Input
    5 10
    8
    1 4
    2 4
    2 5
    2 6
    1 6
    3 5
    3 4
    4 4
    4
    1 5
    2 7
    3 7
    3 6
    
    Expected output
    NO
    YES
    YES
    NO
    YES
    
  2. Example 2

    Input
    3 3
    5
    1 1
    1 2
    1 3
    2 3
    3 3
    4
    2 1
    3 2
    3 1
    2 2
    
    Expected output
    YES
    NO
    NO
    NO
    YES