#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table

#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define sz(a) (int) a.size()
#define bitcount(a) (int) __builtin_popcount(a)
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define bitat(n, a) (((ll)n>>a)&1LL)

using namespace std;
// using namespace __gnu_pbds;


typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;

template <typename T>
inline void read(vector<T>& v) {
    for (T& i : v) cin >> i;
}

const int MOD = 1000000007;

bool solve(int i) {
    int n;

    cin >> n;

    vll arr(n);
    read(arr);

    vll num(60, 0);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 60; j++) {
            num[j] += bitat(arr[i], j);
        }
    }
    ll tot = 0;

    for (int i = 0; i < n; i++) {
        ll a = 0, b = 0;
        for (int j = 0; j < 60; j++) {
            a += bitat(arr[i], j)*((1LL<<j)%MOD)*num[j];
            b += (bitat(arr[i], j) ? n : num[j])*((1LL<<j)%MOD);
        }
        a %= MOD; b %= MOD;
        tot = (tot+a*b)%MOD;
    }

    cout << tot << "\n";

    return false;
}   


int main() {
    // freopen("input.in", "r", stdin);
    // freopen("input.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    int t; cin >> t; for(int i = 1; i <= t; ++i) solve(i); /*
    for (int i = 1; solve(i); i++); /**/
    cout.flush();
    return 0;
}