#P2334. Room

Room

The ACM / ICPC team has a large room, the length and width of which is 10 6 .

However, the guys in ACM / ICPC teams are too lazy to make their study room tidy. So there

are wires everywhere and divide the room into several parts. A team in a part of the room cannot

move out of it or they might touch the wires and the network will down. To make every team can

compete in the contest, they have to set up some facilities such as toilet since the teams should

do anything in their parts.

Now, we will give you the map of our study room and the position of the teams, your task is

to calculate how many facilities is required to let every team can access a facilities to finish the

contest without move out of their part.

You should note that two or more teams can share a facility.

Input

The first line of input is an integer n (0 ≤ n ≤ 100000), means how many wires in the room.

The next n lines, each line contains four integers (x a ,y a ), (x b ,y b ), the coordinate of two ends of

the wire, you should note that both of ends are pinned to walls so that at least one of x a and y a

is 0 or 10 6 , and at least one of x b , y b equals to 0 or 10 6 .

The next line is an integer t (0 ≤ t ≤ 100), means how many teams in the room.

The next t lines, each line contains two integers (x i ,y i ), the coordinate of team i.

No teams will sit on the wires since it is too dangerous.

Output

Output one integer, the minimal facilities required.

Sample Input

3
0 200000 1000000 600000
600000 0 300000 1000000
0 800000 1000000 400000
9
200000 900000
200000 400000
300000 600000
600000 500000
700000 700000
800000 300000
300000 200000
800000 100000
600000 200000

Sample Output

6

HINT

The sample data looks like the following picture.


Page 11 of 17

Source