#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

const int mod = 1e9+7;

void f(int& x){
    if (x >= mod)
        x %= mod;
}

int g(int x){
    f(x);
    return x;
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int t;
    cin >> t;

    for (int e = 0; e < t; ++e){
        int n;
        cin >> n;

        vi a(n), cnt(60);
        for (auto& i : a){
            cin >> i;

            for (int j = 0; j < 60; ++j)
                if ((1ll << j) & i)
                    ++cnt[j];
        }

        vi suma(n, 0);
        for (int i = 0; i < n; ++i){
            for (int j = 0; j < 60; ++j){
                if (a[i]&(1ll<<j)){
                    suma[i] += g(cnt[j] * g(1ll << j));
                    f(suma[i]);
                }
            }
        }

        int sol = 0;
        //for (int i = 0; i < n; ++i){
            for (int j = 0; j < n; ++j){
                int x = suma[j];
                f(x);

                for (int k = 0; k < 60; ++k){
                    int y = 1ll << k;
                    f(y);
                    if ((1ll << k) & a[j]){
                        sol += g(n*g(y * x));
                        f(sol);
                    } else {
                        sol += g(g(x * cnt[k])*y);
                        f(sol);
                    }
                }

//                cout << sol << '\n';
            }
    //    }

        cout << sol << '\n';
    }
}