C. The Robbery of Ahl Homs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Unfortunately, the HCPC was cancelled only hours before the contest, by which time the T-shirts had already arrived. However, because everyone was fighting with everyone else at that moment, no one noticed their arrival except for one man: the big, big thief! He ran off with all the T-shirts, washed them, and put them on his clotheslines to dry.

There are $$$n$$$ horizontal clotheslines, numbered from $$$1$$$ to $$$n$$$ from top to bottom. Each clothesline initially holds exactly $$$m$$$ HCPC T-shirts. A T-shirt is described by its horizontal coordinate $$$x$$$. The coordinates of the T-shirts on the same clothesline are pairwise distinct.

When a T-shirt falls, every T-shirt with the same coordinate on a lower clothesline falls as well. All such T-shirts fall simultaneously. A fallen T-shirt is removed permanently. Fallen T-shirts remain absent in later queries.

Since the big, big thief stole those clotheslines a loooooooong time ago, some of them have begun to fall. You must process $$$q$$$ queries. In each query, clothesline $$$r$$$ falls, and every T-shirt still present on it falls too. The resulting cascade is then applied. No clothesline is queried more than once. For each query, find the number of T-shirts that fall during that query.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.

The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 2 \cdot 10^5$$$, $$$n \cdot m \le 2 \cdot 10^5$$$) — the number of clotheslines and the initial number of T-shirts on each clothesline.

Each of the next $$$n$$$ lines contains $$$m$$$ integers $$$x_{i,1},x_{i,2},\ldots,x_{i,m}$$$ ($$$1 \le x_{i,j} \le 10^9$$$), the coordinates of the T-shirts on clothesline $$$i$$$. The coordinates in each of these lines are pairwise distinct.

The next line contains an integer $$$q$$$ ($$$1 \le q \le n$$$) — the number of queries.

Each of the next $$$q$$$ lines contains an integer $$$r$$$ ($$$1 \le r \le n$$$), meaning that clothesline $$$r$$$ falls. All queried clotheslines in a test case are pairwise distinct.

It is guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For every query, print one integer — the number of T-shirts that fall during that query.

Example
Input
1
3 2
1 2
2 3
1 3
3
2
1
3
Output
3
3
0
Note

The following diagram illustrates the first query of the example. Each blue circle is a T-shirt, and its number is its horizontal coordinate. The red crosses mark the T-shirts that fall.

In the first query of the example, the two T-shirts on clothesline $$$2$$$ fall. The T-shirt at coordinate $$$3$$$ also makes the T-shirt at coordinate $$$3$$$ on clothesline $$$3$$$ fall, so the answer is $$$3$$$.

In the second query, both T-shirts on clothesline $$$1$$$ fall. They make the remaining T-shirt at coordinate $$$1$$$ on clothesline $$$3$$$ fall. The answer is again $$$3$$$.

Clothesline $$$2$$$ is already empty during the final query, so its answer is $$$0$$$.