题目描述
You are given arrays A and B of length N each. Determine the number of good pairs.
A pair (i,j) (1≤ i,j ≤ N) is said to be good if all of the following conditions are satisfied:
i < j;
A_{i} = B_{j};
A_{j} = B_{i};
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
Description of each test case:
- First line contains an integer N - denoting the length of the arrays.
- Second line contains $N space-separated integers A_{1}, A_{2}, \dots A_{N} -$ denoting the array A.
- Third line contains $N space-separated integers B_{1}, B_{2}, \dots B_{N} -$ denoting the array B.
------ Output Format ------
For each test case, output the number of good pairs.
------ Constraints ------
$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
3
1 2 3
3 2 1
4
1 2 3 4
5 6 6 7
3
10 10 10
10 10 10
4
4 8 1 1
8 4 1 1
----- Sample Output 1 ------
1
0
3
2
----- explanation 1 ------
Test Case $1$: The only good pair $(i,j)$ is $(1,3)$. Here,
- $1 < 3$
- $A_{1} = 1$ and $B_{3} = 1$. Thus, $A_{1} = B_{3}$.
- $A_{3} = 3$ and $B_{1} = 3$. Thus, $A_{3} = B_{1}$.
Test Case $2$: There are no good pairs.
Test Case $3$: There are $3$ good pairs $(i,j)$. These are $(1,2), (1,3),$ and $(2,3)$.
Test Case $4$: There are $2$ good pairs $(i,j)$. These are $(1,2)$ and $(3,4)$.
输入格式
见题面
输出格式
见题面