Loading...
OR Pairs
Time: 3 s
Memory: 125 MB
Rakib has recently found an array \(a\) of \(n\) non-negative integers. Seeing this, Rakib's friend Akash has come up with a challenge for him. Akash has constructed another array \(b\), consisting of \(n\) non-negative integers. Akash challenged Rakib to find the count of pairs of indices \((i,j)\) such that the bitwise OR of \(a_i\) and \(a_j\) is present in the array \(b\) (\(i\) and \(j\) can be equal). After being challenged, Rakib said, "This problem is so easy that I can solve it in under 10 minutes."

Unfortunately, Rakib could not solve it in under 10 minutes. Can you help him? Also, for an unknown reason, you need to print the answer multiplied by \(2\).
Input
The first line contains a single integer \(t\) \((1 \leq t \leq 500)\) — the number of test cases.
The first line of each test case contains a single integer \(n\) \((1 \leq n \leq 10^5)\) — the size of the arrays. 
The second line of each test case contains \(n\) integers \(a_1, a_2, \dots, a_n\) \((0 \leq a_i \leq 10^9)\) — the array \(a\). It is guaranteed that \(a_i\) is a product of the powers of \(2\) and \(3\).
The third line of each test case contains \(n\) integers \(b_1, b_2, \dots, b_n\) \((0 \leq b_i \leq 10^9)\) — the array \(b\).
It is guaranteed that the sum of \(n\) over all test cases doesn't exceed \(2 \cdot 10^5\).
Output
For each test case, print a single integer — described in the statement.
Examples
Input
Output
2
2
1 2
3 1
3
1 2 4
5 6 7
6
8
Notes
In the first testcase of the first example, there are \(3\) pairs: \(a_1\) OR \( a_1 = 1\),  \(a_2\) OR \( a_1 = 3\),  \(a_1\) OR \( a_2 = 3\). Both \(1\) and \(3\) are present in the array \(b\).
Problem Info
Problem ID 275
Time Limit 3000 ms
Memory Limit 128000 KB
Moderators amirhozaifa , fahimcp495
Statistics
Submit
You need to Login or Registration for submit your solution