#include<bits/stdc++.h>
#define lld long long int
#define ll long double
#define vlld vector <lld>
#define vll vector <ll>
#define vvlld vector <vlld>
#define vvll vector <vll>
#define plld pair <lld,lld>
#define pll pair <ll,ll>
#define vplld vector <plld>
#define vpll vector <pll>
#define F first
#define S second 
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

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

lld modInverse(lld n, lld p)
{
    return po(n, p - 2, p);
}

// lld per(lld n, lld r, lld p)
// {
//     if (r == 0)
//         return 1;
 
//     return (fact[n] * modInverse(fact[r], p) % p * modInverse(fact[n - r], p) % p) % p;
// }



int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ios;
    lld t;cin>>t;
    while(t--)
    {
    	lld n;
    	cin>>n;
    	vlld x(n);
    	rep(i,0,n)cin>>x[i];

    	vlld v(62,0);

    	rep(i,0,n){
    		rep(j,0,62){
    			if((x[i]>>j)&1)v[j]++;
    		}
    	}

    	vlld an(n),r(n);

    	lld res=0;
    	rep(i,0,n){

    		lld av=0,ov=0,p;
    		rep(j,0,62){
    			p=(1LL<<j)%mod;
    			if((x[i]>>j)&1){
    				av=(av+p*v[j])%mod;
    				ov=(ov+p*n)%mod;
    			}
    			else{
    				ov=(ov+p*v[j])%mod;
    			}

    		}

    		res=(res+av*ov)%mod;

    	}

    	cout<<res<<endl;
    }
}