Opening a Restaurant
Time limit5sMemory limit128 MB
Count the grid intersections that beat every existing restaurant in distance to apartment A or to apartment B.
Problem
You want to open a new restaurant. The city is an grid. Every road is either vertical or horizontal, and the roads in each direction are numbered from to . Every restaurant sits at an intersection, and an intersection is written as a coordinate , the pair (vertical road number, horizontal road number). The distance between two intersections and is .
The city has two large apartment buildings and that lie on the same horizontal road (that is, they share the same coordinate). Both apartments already have a restaurant.
Because the residents of the two apartments meet often, you want to place the new restaurant somewhere between them. However, once the existing restaurants and rent are taken into account, the exact midpoint is not always best. So you look for a "good place" defined as follows, where is the distance between and .
An intersection is a "good place" if, for every existing restaurant , or . In other words, is not a good place if there is any restaurant that satisfies and at the same time.
The restaurants that are compared include the ones at the two apartments and .
For example, consider an city with apartments and .
- is a good place.
- is not a good place because of the restaurant (here and ).
- is not a good place because of the restaurant at apartment .
Given the positions of the existing restaurants, count how many of the intersections of the city are good places.
Input
The first line contains the number of test cases . For each test case, the first line contains the city size and the number of restaurants (, ). Each of the next lines contains the coordinates , of a restaurant ().
No two restaurants share the same coordinates. Apartment is at the first restaurant and apartment is at the second restaurant, and and lie on the same horizontal road.
Output
For each test case, print the number of good places on its own line.