You are given a tree G with N nodes. The ith node of the tree has been assigned value Ai. We define d(u,v) as the bitwise xor of weight of nodes present on the simple path between u and v. You are required to find:
N∑i=1N∑j=i+1d(i,j)
Input format
Output format
For each test case(in a separate line), output the sum N∑i=1N∑j=i+1d(i,j), where d(i,j) is the bitwise xor of weight of nodes present on the simple path between i and j.
Constraints
1≤T≤10001≤N≤1051≤Ai≤109Sum of N over all test cases does not exceed 106
In the first test case, we have A1=1,A2=3,A3=4. The tree looks as follows:
We have d(1,2)=A1⊕A2=2, d(1,3)=A1⊕A3=5, d(2,3)=A2⊕A1⊕A3=6. The sum is d(1,2)+d(1,3)+d(2,3)=2+5+6=13 and we output it.
In the second test case, there is only one edge and we find d(1,2)=A1⊕A2=2 and output it.