Problem B

Statement
Copy Copied
B. Gamestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice 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.InputThe 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.OutputFor each test case, print a single integer — the maximum possible number of suggestions they will make while choosing which game to play.ExampleInput32 31 22 3 51 1554 21 3 4 74 6Output3
1
4
NoteIn 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.