You are given two arrays of size n1 and n2. Your task is to find all the elements that are common to both the arrays and sum them print them in the order as they appear in the second array. If there are no common elements the output would be 0.
Note: The arrays may contain duplicate elements. However, you need to sum only unique elements that are common to both arrays.
The first line of input contains T denoting the number of testcases. T testcases follow. Each testcase contains two three lines of input. The first line contains n1 and n2 separated by a space. The second line contains elements of arr1. The third line contains elements of arr2.
For each testcase, in a new line, print the common sum.
Since this is a function problem, you don't need to take any input. Just complete the provided function commonSum that takes two arrays as input.