 Sum the common elements
Basic Accuracy: 46.14% Submissions: 880 Points: 1

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.

Input Format:
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.

Output Format:
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.

Constraints:
1 <= T <= 100
1 <= n1,n2 <= 1000
1 <= arr1i,arr2i <= 109

Example:
Input:

1
5 6
1 2 3 4 5
2 3 4 5 6 7
Output:
14 