#include <math.h>
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define int ll
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

const ll MOD = 1000000007;

ll t, n;
ll x[1000000];
ll da[100];
ll tmp;

signed main() {
    cout.precision(15);
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>t;
    while (t--) {
        cin>>n;
        for (int i = 0; i < 80; i++) da[i] = 0;
        for (int i = 0; i < n; i++) {
            cin>>tmp;
            for (int j = 0; j < 60; j++) {
                if (tmp & (1LL<<j)) {
                    da[j] += (1LL<<j);
                    da[j] %= MOD;
                }
            }
            x[i] = tmp;
        }
        int ans = 0;
        for (int j = 0; j < n; j++) {
            int sum1 = 0;
            int sum2 = 0;
            tmp = x[j];
            for (int i = 0; i < 60; i++) {
                if (tmp & (1LL << i)) {
                    sum1 += da[i];
                    sum2 += ((1LL<<i)%MOD) * n;
                    sum2 %= MOD;
                    sum1 %= MOD;
                } else {
                    sum2 += da[i];
                    sum2 %= MOD;
                }
            }
            sum1 %= MOD;
            sum2 %= MOD;
            ans += sum1 * sum2;
            ans %= MOD;
        }
        cout << ans << endl;
    }
    return 0;
}
