Intermediate1200

Games

Codeforces
View on Codeforces
Time: 2 secondsMemory: 256 megabytes

Alice and Bob are planning to play an online game together but haven't decided on which one yet. Alice has a list of n games she enjoys: a_1, a_2, …, a_n. Bob, on the other hand, has a list of m games he likes: b_1, b_2, …, b_m. They share at least one game in common between their lists.

To choose a game, they take turns suggesting games from their lists. Alice begins by suggesting one of her favorite games. If Bob likes it, they play that game. If not, Bob suggests one of his favorite games. If Alice likes it, they play that game. This alternating process continues, with Alice and Bob each suggesting games from their lists in turn, ensuring that no game is suggested more than once.

Your task is to calculate the maximum possible number of suggestions they will make while choosing which game to play.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 100).The second line contains n integers a_1 a_2 ·s a_n (1 ≤ a_i ≤ 100).The third line contains m integers b_1 b_2 ·s b_m (1 ≤ b_i ≤ 100).Arrays a and b contain at least one common integer.

Output

For each test case, print a single integer — the maximum possible number of suggestions they will make while choosing which game to play.

Examples

Input
3 2 3 1 2 2 3 5 1 1 5 5 4 2 1 3 4 7 4 6
Output
3 1 4

Note

In the first test case, the maximum number of suggestions is 3. It is achieved as follows: Alice suggests game 1, but Bob does not like it; Bob suggests game 5, but Alice does not like it; Alice suggests game 2, which Bob likes, and they go to play that game. In the second test case, Alice can only suggest game 5, which Bob likes, so they will immediately go to play it.In the third test case, the maximum number of suggestions is 4. It is achieved as follows: Alice suggests game 7, but Bob does not like it; Bob suggests game 6, but Alice does not like it; Alice suggests game 1, but Bob does not like it; Bob suggests game 4, which Alice likes, and they go to play it.

*specialgreedy

Discussion

(0)
Sign in to join the discussion.
Loading editor...
0 online