In country X, there are cities and one-way roads, and all city can reach city 1. One query will
give 3 sets of cities A, B, C. Alice will choose a city x in set A, choose a city z in set C, and walk from x
to z (if x can reach z). Bob will choose a city y in set B, and walk from y to z (if y can reach z). How
many cities can possibly be the city where Alice and Bob meet each other?
In other words, how many cities can be reached from any city in set A, any city in set B, and can reach
any city in set C?
There are test cases, and each case has queries.
输入格式
First line is one integer , indicating test cases. In each case:
First line is 2 integers , indicating cities and queries.
Next line is integers , the -th integer indicates the road from city to city
.
Next is queries, in each query:
First line is 3 integer , indicating the size of set A, B, C.
Next line is integers, indicating the set .
Next line is integers, indicating the set .
Next line is integers, indicating the set .
for all cases
for all queries in all cases .
1 ≤ T ≤ 20, 1 ≤ n,q,∣A∣,∣B∣,∣C∣ ≤ 2 × 10 ,
∑ n ≤ 2 × 10 ,
∑ q ≤ 2 × 10 ,
输出格式
In each case, print integers, one integer per line, -th integer indicates the answer of -th query.