INS14K - Digo Goes Training


Digo is being trained for shooting as it is a very integral part of his missions. His trainer sets up a training arena for him to practice for it. Digo is taken to the ground where many strong penetrable walls are placed in arbitrary manner. Consider the ground to be a rectangular grid with cartesian coordinates. Digo fires the bullets from a given point on the X-axis. The bullets can only travel parallel to the Y-axis. Given the endpoints of the walls and Digo's current position on the X-axis, he wants to know how many walls he will penetrate with each shot. The shots will only penetrate the wall, they are not powerful enough to break them. As he is very weak in mathematics, he asks you to help him.

Input

The first line consists of the number of test cases, T. The second line contains the number of walls N. Then N lines follow, each line contains 4 integers denoting the end-points of the walls i.e. x1 y1 x2 y2. Next line denotes Q, the number of queries. Queries can be of two types:

  • 1 x1 y1 x2 y2 : which denotes the endpoints of new wall placed.
  • 0 pos : where pos tells about the x coordinate of Digo’s position. The position will be a floating point number, having exactly two digits after the decimal place.

Output

For each query of the type ‘0 pos’ output the numbers of walls penetrated.

Constraints

1 <= T <= 10
1 <= N <= 1000
1 <= Q <= 1000
0 <= x1, y1, x2, y2 <= 20000
0.00 <= pos <= 20000.00

Sample

Input:
1
3
3 5 7 8
1 3 5 6
2 4 8 9
4
0 6.73
1 4 7 9 8
1 2 5 6 3
0 3.55

Output:
2
4

hide comments
Jacob Plachta: 2014-03-22 04:37:51

It seems that pos is never an integer (its decimal part is always non-zero), so hitting exactly the endpoint of a wall isn't an issue.


Added by:Surya Kiran
Date:2014-03-20
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Insomnia 2014