Given two arrays **A** and **B** of size **N** and **M** respectively. The task is to find union between these two arrays.

Union of the two arrays can be defined as the set containing distinct elements from both the arrays. If there are repetitions, then only one occurrence of element should be printed in union.

**Input:**

The first line of input contains an integer **T** denoting the number of test cases. Then T test cases follow. Each test case consist of three lines. The first line of each test case contains two space separated integers *N* and *M*, where *N* is the size of array *A* and *M* is the size of array *B*. The second line of each test case contains *N *space separated integers denoting elements of array *A*. The third line of each test case contains *M* space separated integers denoting elements of array *B*.

**Output:**

Correspoding to each test case, print the count of union elements of the two arrays.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ N, M ≤ 10^{5}

1 ≤ A[i], B[i] < 10^{5}

**Example:**

**Input:**

2

5 3

1 2 3 4 5

1 2 3

6 2

85 25 1 32 54 6

85 2

**Output:**

5

7

**Explanation:
Testcase 1: **1, 2, 3, 4 and 5 are the elements which comes in the union set of both arrays.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

_Shubham_Jain_06 | 404 |

maggiiiii | 315 |

Savage_19 | 310 |

ritikdagar0203 | 241 |

thanuvinu94 | 233 |

Bishnu Dev Panda | 810 |

_Shubham_Jain_06 | 715 |

okayboss | 652 |

maggiiiii | 598 |

Savage_19 | 576 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.