#P7209. Bowling

    ID: 6066 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2022“杭电杯”中国大学生算法设计超级联赛(7)

Bowling

Problem Description

Little Rabbit has recently become interested in a special kind of bowling. The bowling ball can be seen as a convex polygon on a two-dimensional plane. And the pins (the target of the bowling ball) can be seen as points on the plane.

As with regular bowling, the goal is to make the bowling ball hit as many pins as possible. We can suppose that the bowling ball makes a translational motion on the plane. Once the pin touches the bowling ball (including the boundary), the pin will be knocked down and will not affect the direction of the bowling ball's motion.

Now given the position of the bowling ball and the pins, for different directions of the bowling ball's motion, please calculate how many pins it can knock down.

Input

The first line of the input contains an integer $T$ ($1 \le T \le 100$), indicating the number of test cases.

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

Each of the next $n$ lines contains two integers $x,y$ ($|x|,|y|\le 10^9$), indicating that the coordinates of a vertex of the convex polygon are $(x,y)$. The vertices are given in counterclockwise order, and there are no three vertices collinear.

The next line contains an integer $m$ ($1 \le m \le 10^5$), indicating the number of pins.

Each of the next $m$ lines contains two integers $x,y$ ($|x|,|y|\le 10^9$), indicating that the coordinates of a pin are $(x,y)$. It is guaranteed that the pins are located strictly at the outside of the polygon.

The next line contains an integer $q$ ($1 \le q \le 10^5$), indicating the number of queries.

Each of the next $q$ lines contains two integers $x,y$ ($|x|,|y|\le 10^9$), indicating that the direction vector of the bowling ball's motion is $(x,y)$. It's guaranteed that $(x,y)\neq (0,0)$.

It is guaranteed that $\sum n$, $\sum m$, and $\sum q$ over all test cases do not exceed $2\times10^5$.

Output

For each query, output an integer in a single line indicating the number of pins the bowling ball can knock down.

1 4 0 0 2 0 2 2 0 2 5 1 4 3 1 4 2 5 1 3 3 3 0 1 1 0 1 1
1 3 3