CF2141B Games

Description

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, \\dots, a\_n$$$. Bob, on the other hand, has a list of $$$m$$$ games he likes: $$$b\_1, b\_2, \\dots, 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 Format

The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 100$$$). The second line contains $$$n$$$ integers $$$a\_1 < a\_2 < \\cdots < a\_n$$$ ($$$1 \\le a\_i \\le 100$$$). The third line contains $$$m$$$ integers $$$b\_1 < b\_2 < \\cdots < b\_m$$$ ($$$1 \\le b\_i \\le 100$$$). Arrays $$$a$$$ and $$$b$$$ contain at least one common integer.

Output Format

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

Explanation/Hint

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.