//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll                   long long
#define skip                 cin>>ws;
#define vll                  vector<ll> 
#define vi                   vector<int>
#define vb                   vector<bool>
#define vpll                 vector<pair<ll,ll>>
#define vvll                 vector<vector<ll>>
#define vvi                  vector<vector<int>>
#define pll                  pair<ll,ll>
#define vs                   vector<string>
#define vvpll                vector<vector<pair<ll, ll>>>
#define pb                   push_back
#define pob                  pop_back()
#define MOD                  (ll)(1e9 + 7)
#define MOD2                 (ll)(998244353)
#define INF                  (ll)(1e18 + 5)
#define count1(n)            __builtin_popcountll(n)
#define test                 ll t; cin>>t; while(t--)
#define enter(a)             for(ll i=0;i<a.size();i++) cin>>a[i];
#define show(a)              for(ll e: a) cout<<e<<" "; cout<<"\n";

using namespace std;

ll mo(ll a){ return a%MOD;}

ll po(ll x, ll y, ll p)
{
    ll res = 1; x = x % p;   
    while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } 
    return res%p; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    test
    {
        ll n;
        cin>>n;

        vll a(n);
        enter(a);

        vll ze(61), on(61);

        for(ll i=60;i>=0;i--)
        {
            for(ll j=0;j<n;j++)
            {
                if((1LL<<i)&a[j]) on[i]++;
                else ze[i]++;
            }
        }

        ll ans = 0;

        vll p2(61);
        for(ll i=0;i<61;i++) p2[i] = po(2, i, MOD);

        for(ll i=0;i<n;i++)
        {
            ll sum = 0;
            for(ll k = 0;k<=60;k++)
            {
                sum =  mo(sum + mo(((a[i]&(1LL<<k))?n: on[k])*p2[k]));
            }

            for(ll j = 0;j<=60;j++)
            {
                if(a[i]&(1LL<<j))
                {
                    ans = mo(ans + mo(on[j]*mo(p2[j]*sum)));
                }
            }
        }

        cout<<ans<<"\n";
    }

    return 0;
}   