#GREED. Greedy island

Greedy island

Gon is on Greedy island. He wants to go home. But to get the ticket to leave the game, he has to get N cards labeled in a sequence from 1 to N (the order of the cards in his hand is irrelevant). He already has N cards, but not forming a sequence from 1 to N. So he wants you to help him. For some cards, he can change one card for another for one piece of gold. Help him to get the ticket at the minimum cost (using the minimum number of exchanges).

Input

The first line contains t, the number of tests (1<=t<=10). For each test case:

  • the number of cards N is given is given in the first line (2<=N<=500).
  • the next N lines contain the N cards owned by Gon.
  • the following line contains e, the number of different allowed types of exchanges.
  • the next e lines contain two integers xi,yi each which mean that we can exchange and replace the card marked x by the card marked y and vice versa.

There is a blank line after each test case.

Output

For each test case, output a line denoting the minimum required cost.

Example

Input:
1
4
1
2
2
2
2
2 3
3 4

Output: 3

</p>