#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define F first
#define S second

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())

using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;

template<class T> bool ckmin(T& a, T b) { return b < a ? a = b, true : false; }
template<class T> bool ckmax(T& a, T b) { return b > a ? a = b, true : false; }

const int MOD = 1e9+7;

void solve() {
    int n; cin >> n;
    vector<ll> v(n);
    vi cnt(60);
    for (int j = n; j--; ) {
        ll x; cin >> x; v[j] = x;
        for (int i = 0; x != 0; ++i) {
            if (x % 2) ++cnt[i];
            x /= 2;
        }
    }

    int ans = 0;
    for (int j = n; j--; ) {
        int x = 0;
        for (int i = 0, pi = 1; i < 60; ++i) {
            if ((v[j] >> i) & 1) x = (x + (ll)pi * cnt[i]) % MOD;
            pi = 2 * pi % MOD;
        }
        for (int i = 0, pi = 1; i < 60; ++i) {
            int c = ((v[j] >> i) & 1) ? n : cnt[i];
            ans = ((ll)pi*c%MOD*x + ans) % MOD;
            pi = 2 * pi % MOD;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1; cin >> t;
    while(t--) solve();
}