// https://codeforces.com/contest/1466/problem/E

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;

#define IS(x, i) (((x) & (1ll << (i))) != 0)

ll add(ll a, ll b) { return ((a % M) + (b % M)) % M; }
ll mul(ll a, ll b) { return ((a % M) * (b % M)) % M; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int B = 60;
        int n;
        cin >> n;
        vector<ll> v(n);
        vector<int> nrset(64, 0);
        for (ll &x : v) {
            cin >> x;
            if (x > 0) {
                // int b = __builtin_clz(x);
                // B = max(B, 63 - b);
            }
            for (int i = 0; i < B; ++i) {
                if (IS(x, i))
                    nrset[i]++;
            }
        }
        ll ans = 0;
        for (int j = 0; j < n; ++j) {
            const ll xj = v[j];

            ll X = 0;
            for (int i = 0; i < B; ++i) {
                ll w = (1ll << i) % M;
                if (IS(xj, i))
                    X = add(X, mul(w, nrset[i]));
            }

            ll Y = 0;
            for (int i = 0; i < B; ++i) {
                int k = IS(xj, i) ? n : nrset[i];
                Y = add(Y, mul(k, 1ll << i));
            }

            ans = add(ans, mul(X, Y));
        }
        cout << ans << endl;
    }
    return 0;
}
