#P9809. Fencing the cows

Fencing the cows

Fencing the cows

Problem Description

Little ColdHand wants to build a fence to enclose his cows' grazing area. However, in order for the fence to be effective, it must include all mm grass locations. Otherwise, the cows might rebel against him. To address this issue, Little ColdHand sought assistance from the Interstellar Cow Company. However, the company provided him with only nn fence points, and he can only build the fence from a point to another point. The final cost will be the number of points used. Little ColdHand is aware that the most cost-effective fence would be a convex hull, but he doesn't know the exact number of points required for it. Therefore, he has approached you to help solve this problem: Determine the minimum number of points needed to construct a fence that completely encloses all mm grass-eating locations. P.S. If the fence intersects any of the grass locations, we do not consider those locations as fully enclosed.

Input

The first line of input contains the integer TT (1T101 \le T \le 10), the number of test cases. The description of test cases follows. The first line of each test case contains two integers, nn and mm (1n500,1m5001 \le n \le 500, 1 \le m \le 500) — the number of fence points and the number of grass locations. Each of the next nn lines contains the description of fence points. Each line contains two integers xix_i and yiy_i (109xi,yi109-10^9 \le x_i,y_i \le 10^9), describes the fence point aia_i at (xi,yix_i, y_i). Each of the next mm lines contains the description of grass location. Each line contains two integers xix_i and yiy_i (109xi,yi109-10^9 \le x_i,y_i \le 10^9), describes the grass location bib_i at (xi,yix_i, y_i). it is guaranteed that the sum of nn and mm over all test cases both do not exceed 40004000.

Output

For each test case, if any solution exists, output an integer in a line, indicating the minimum cost of fence. otherwise, output 1-1

Sample Input

2
4 1
1 1
1 -1
-1 1
-1 -1
0 0
4 1
1 1
1 -1
-1 1
-1 -1
1 0

Sample Output

4
-1

Source

2023“钉耙编程”中国大学生算法设计超级联赛(2)