#include <bits/stdc++.h>
using namespace std;

const int N = 500000 + 9;
const long long M = 1000000007;

long long a[N];
long long cnt[100], b[100];
long long Pow2[100];


void solve(){
    int n; scanf("%d", &n);
    memset(cnt, 0, sizeof(cnt));
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; ++i){
        scanf("%lld", a + i);
        for (int p = 0; p < 60; ++p){
            if (a[i] >> p & 1) ++cnt[p];
        }
    }
    for (int i = 1; i <= n; ++i){
        long long sum = 0;
        for (int p = 0; p < 60; ++p){
            if (a[i] >> p & 1){
                sum = (sum + n * Pow2[p] % M) % M;
            }
            else {
                sum = (sum + cnt[p] * Pow2[p] % M) % M;
            }
        }
        for (int p = 0; p < 60; ++p){
            if (a[i] >> p & 1){
                b[p] = (b[p] + sum) % M;
            }
        }
    }
    long long ans = 0;
    for (int p = 0; p < 60; ++p){
        ans = (ans + Pow2[p] * cnt[p] % M * b[p] % M) % M;
    }
    printf("%lld\n", ans);
}

int main(){
    Pow2[0] = 1;
    for (int i = 1; i <= 60; ++i){
        Pow2[i] = Pow2[i - 1] * 2 % M;
    }
    int T; scanf("%d", &T);
    while (T--) solve();
    return 0;
}