//https://www.hackerrank.com/challenges/xoring-ninja
import java.io.*;

public class Solution {
    
    final static int MOD = 1000000007;
    
    public static void main(String[] args) throws IOException {
        StringBuffer sb = new StringBuffer();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        //For each test case
        for(byte T = Byte.parseByte(br.readLine()); T > 0; --T){
            
            //Get input set
            final int[] A = new int[Integer.parseInt(br.readLine())];
            int N = 0;
            for(String a : br.readLine().split(" ")){
                A[N++] = Integer.parseInt(a);
            }
            
            //Get set bits
            int bits = 0;
            for(int i = 0; i < N; bits |= A[i++]){}
            
            //Get xorSum
            int xorSum = 0;
            for(byte i = 0; bits > 0; ++i){
                if((bits & 1) == 1){
                    xorSum = (xorSum + powMod(2, N - 1 + i, MOD)) % MOD;
                }
                bits >>= 1;
            }
            
            //Print output
            sb.append(xorSum + "\n");
        }
        System.out.print(sb);
    }
    
    private static int powMod(int b, int p, final int m){
        int v = 1;
        while(p > 0){
            if ((p & 1) == 1){
                v = (int)((1L*v*b) % m);
            }
            p >>= 1;
            b = (int)((1L*b*b) % m);
        }
        return v;
    }
}

@@ -861,24 +861,71 @@
 xorSum = 0;%0A
+            final int x = powMod(2, N-1, MOD);%0A
             
@@ -1022,16 +1022,22 @@
 orSum = 
+(int)(
 (xorSum 
@@ -1042,40 +1042,31 @@
 m + 
-powMod(2, N - 1 + i, MOD
+(((long)x) %3C%3C i
 )) %25 MOD
 ;%0A  
@@ -1061,16 +1061,17 @@
 )) %25 MOD
+)
 ;%0A      

Update xoring-ninja.java