A reverse geocoding service maps coordinates to geographic regions. In this problem, you must implement such a service.
You are given geographic regions. Each region is an axis-aligned rectangle in the plane: its sides are parallel to the coordinate axes. It is described by two opposite corners and , with and . For any two regions, either one is strictly contained in the other or they are disjoint. Their boundaries do not touch or cross.
The service must answer location queries. Each query is given by three integers , and . The point is the measured location, and describes the uncertainty of the measurement: the actual location can be any point inside or on the boundary of the axis-aligned query square with opposite corners and . When , the query square consists of the single point .
It is guaranteed that no corner of a query square lies on the boundary of any region. However, the boundary of a query square may intersect region boundaries.
For each query, determine the region of smallest area that is guaranteed to contain the actual location. In other words, find the region of smallest area that contains the entire query square, or report that no such region exists.
The first line contains an integer () indicating the number of geographic regions. Each region is identified by a distinct integer from to .
The -th of the next lines describes region with four integers , , and (, and ), where and are two opposite corners of the corresponding rectangle.
The next line contains an integer () indicating the number of location queries.
Each of the next lines describes a query with three integers , and ( and ), representing the query square with opposite corners and . The corners of this square may lie outside the coordinate range given for and .
For each query in the input, output a line with an integer
identifying the region of smallest area that contains the entire query
square. If no region contains the entire query square, output a line
with the character “*” (asterisk) instead.
2 0 0 10 10 2 2 6 6 3 4 4 1 4 4 3 9 5 2
2 1 *
Solid rectangles: regions
Qi: i-th query (square or point)
Q1 → 2
Q2 → 1
Q3→
*
3 2 2 4 4 8 0 14 6 0 0 6 6 4 3 3 0 1 1 0 11 3 1 7 3 2
1 3 2 *
Q1 → 1
Q2 → 3
Q3 → 2
Q4→
*
1 -1 -1 1 1 3 0 0 0 1 3 0 0 0 2
1 * *
Q1 → 1
Q2→
*
Q3→
*