Universal Cup Judging System

Universal Cup

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

A polygon $P_1$ contains polygon $P_2$ if every point in or on $P_2$ is also in or on $P_1$. A polygon $P_1$ strictly contains $P_2$ if every point in or on $P_2$ is strictly inside $P_1$ (no point on the boundary).

Panda has two convex polygons, $P$ and $Q$. Polygon $P$ has $n$ vertices, and polygon $Q$ has $m$ vertices. It is guaranteed that $Q$ is strictly contained by $P$.

You should help Panda find the total number of ways to choose exactly $3$ distinct vertices from polygon $P$ that form a triangle $P_\Delta$ such that $P_\Delta$ (not strictly) contains polygon $Q$.

Figure 1

Input

The first line contains a single integer $T$ ($1 \le T \le 1000$), denoting the number of test cases.

For each test case, the first line contains an integer $n$ ($3 \le n \le 3 \cdot 10^5$), denoting the number of vertices of $P$.

For the next $n$ lines, each line contains two integers $x, y$ ($|x|, |y| \le 10^9$), denoting the coordinates of the vertices of $P$. It is guaranteed that the vertices are given in counter-clockwise order, and no three vertices are collinear.

The next line contains an integer $m$ ($3 \le m \le 3 \cdot 10^5$), denoting the number of vertices of $Q$.

For the next $m$ lines, each line contains two integers $x, y$ ($|x|, |y| \le 10^9$), denoting the coordinates of the vertices of $Q$. It is guaranteed that the vertices are given in counter-clockwise order, and no three vertices are collinear, and $Q$ is strictly contained by $P$.

It is guaranteed that both $\sum n$ and $\sum m$ over all test cases do not exceed $5 \cdot 10^5$.

Output

For each test case, output an integer in a single line, denoting the answer.

Examples

Input 1

3
6
-5 0
-4 -4
0 -4
3 1
2 5
-3 4
4
-2 1
-2 0
0 0
0 1
6
-5 0
-4 -4
0 -4
3 1
2 5
-3 4
4
-1 1
-1 0
0 0
0 1
7
1 -3
4 -1
5 0
1 4
0 4
-1 0
0 -2
3
0 0
2 0
0 2

Output 1

2
4
6

Note

For the first example, as shown in the figure, the polygon $P$ is $ABCDEF$, and the polygon $Q$ is $GHIJ$. The triangles $\triangle ACE$ and $\triangle BDF$ are the ones that contain $Q$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.