#P7482. [2017年杭电多校]Rikka with Terrorist
[2017年杭电多校]Rikka with Terrorist
Rikka with Terrorist
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: In an ancient country, there are cities. The coordinate of the th city is . There are tourists. Initially, the th tourist is at city and all of them want to go out and play in other cities. Unfortunately, of the cities has been controlled by terrorists, so these cities became unsafe. For safety, the tourist whose initial coordinate is can go to the city if and only if all of the city $(x,y)(\min(x1,x2) \leq x \leq \max(x1,x2),\min(y1,y2) \leq y \leq \max(y1,y2))$ is safe. Now, for each tourist, Yuta wants to know the number of cities he can reach safely (including the initial city he stayed). It is too difficult for Rikka. Can you help her? In the sample, the third tourist can reach .
Input
The first line contains a number , the number of the testcases. There are at least testcases with . For each testcase, the first line contains four numbers .
Then lines follow, each line contains two numbers -- the coordinate of an unsafe city. It is guaranteed that the coordinates are different from each other. Then lines follow, each line contains two numbers -- the initial city of each tourist. It is guaranteed that initially each tourist stays at a safe city.
Output
For each tourist, print a single line with a single number -- the answer.
Sample Input
1
4 5 4 4
1 2
2 5
3 3
4 5
1 5
2 1
2 4
4 1
Sample Output
3
9
8
9
Source
2017 Multi-University Training Contest - Team 5