Cow Confinement

Each cow moves only down or right across a large grid and cannot cross rectangular fences, and the task asks how many flowers each cow can reach.

Hard8Segment treeSortingIntervalsNo attempts yetTime limit10sMemory limit512 MB

Problem

A pasture is a grid of 10610^6 rows and 10610^6 columns. The rows are numbered 11 through 10610^6 from top to bottom, and the columns are numbered 11 through 10610^6 from left to right.

nn cows stand in the pasture, each on one unit square. The pasture also holds mm dandelion flowers, each on one unit square, and ff fences. A fence is a rectangle whose sides run along the edges of unit squares. No two fences intersect or touch. A fence may lie entirely inside the area another fence encloses.

Because of the wind a cow moves only down or right. A cow on square (r,c)(r, c) steps to (r+1,c)(r + 1, c) or to (r,c+1)(r, c + 1). A cow walks through squares that hold other cows or flowers, but it cannot cross a fence.

For each cow, count the flowers on the squares it can reach from its own square.

Input

The input has three blocks: fences, then flowers, then cows.

The first line of the first block holds the number of fences ff (0f2000000 \le f \le 200000). Each of the next ff lines holds four integers r1r_1, c1c_1, r2r_2, c2c_2 (1r1r21061 \le r_1 \le r_2 \le 10^6, 1c1c21061 \le c_1 \le c_2 \le 10^6) that describe one fence. (r1,c1)(r_1, c_1) is the upper left square inside the fence and (r2,c2)(r_2, c_2) is the lower right square inside the fence. No two fences intersect or touch.

The first line of the second block holds the number of flowers mm (0m2000000 \le m \le 200000). The kk-th of the next mm lines holds two integers rr and cc (1r,c1061 \le r, c \le 10^6), the square of the kk-th flower. No two flowers share a square.

The first line of the third block holds the number of cows nn (1n2000001 \le n \le 200000). The kk-th of the next nn lines holds two integers rr and cc (1r,c1061 \le r, c \le 10^6), the square of the kk-th cow. No two cows share a square, and no cow shares a square with a flower.

Output

Print nn lines. The kk-th line holds the number of flowers the kk-th cow can reach.

Hint

The picture shows the layout of the first example.