Doof on Cartesian Problem Code: CLPNT
You may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built walls to prevent Chef from interrupting him. You have to help Chef by telling him the number of walls he needs to destroy in order to reach Dr Doof.
Formally, the whole area can be represented as the first quadrant with the origin at the bottom-left corner. Dr. Doof is located at the origin . There are walls, the i-th wall is a straight line segment joining the points and . For every initial position of Chef , find the number of walls he needs to break before reaching Doof. Obviously, chef can't start from a point on the wall. Therefore, if lies on any of the given walls, print in a new line.
Input
- First line contains , denoting the number of testcases.
- The first line of every test case contains a single integer denoting the number of walls Dr Doof has built.
- The next line contains space separated distinct integers each denoting .
- The next line contains a single integer denoting the number of times Chef asks for your help.
- The next lines contains two space separated integers and , each denoting the co-ordinates of the starting point of Chef.
Output
For each query, print the number of walls Chef needs to break in order to reach Dr Doof in a separate line. If Chef tries to start from a point on any of the walls, print .
Constraints
- Sum of and over all testcases for a particular test file does not exceed
Sample Input
1
2
1 3
5
0 0
2 0
0 4
1 1
1 2
Sample Output
0
1
2
1
-1
Explanation
The sample input can be represented by the graph given below:
If Chef starts from , he can reach Dr Doof without destroying any wall.
If Chef starts from , he has to destroy the wall.
If Chef starts from , he has to destroy both the walls.
If Chef starts from , he has to destroy the wall.
As lies on the second wall, the answer is for the last query.
Comments
Post a Comment
Please give us your valuable feedback