Architect

Given N tree points and Q axis-aligned polygons of at most 12 vertices, count for each polygon how many trees lie inside it, border included.

Medium6GeometryArrayBrute forceImplementationNo attempts yetTime limit1sMemory limit64 MB

Problem

Matija has a job at a company that builds houses. Every day clients send him orders: they want to build on a particular parcel of land, and Matija has to cut down every tree standing on it. Once all the orders are in, he first has to work out, for each parcel, how many trees are inside it right now, before anything is cut. A tree on the border of a parcel counts as inside it.

You are given the position of every tree in the plane and a description of the parcels the clients are interested in. The size of a single tree is negligible. Each parcel is a polygon with KK vertices, and every edge is either horizontal or vertical. The edges of one parcel never meet each other, while two different parcels may overlap.

Input

The first line has the number of trees in the plane, NN (1N1000001 \le N \le 100\,000). Each of the next NN lines has two integers XX, YY, the coordinates of one tree (X,Y100000|X|, |Y| \le 100\,000). No two trees share the same coordinates.

The next line has the number of client orders, QQ (1Q10001 \le Q \le 1\,000). After it come 2Q2Q lines that describe the orders. Each order takes two lines. The first line has the number of vertices KK of the polygon describing the parcel (4K124 \le K \le 12), and the second line has 2K2K integers listing the coordinates of that parcel's vertices in order, in pairs. Parcel vertex coordinates are also at most 100000100\,000 in absolute value.

The vertices are given in counterclockwise order. For every pair of adjacent edges, one is horizontal and the other is vertical.

Output

Print QQ lines. For each client order print one line holding the number of trees on the matching parcel. Line AA of the output must correspond to order AA of the input.