#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
int main(){
	std::ios::sync_with_stdio(false);
	ll t;
	cin>>t;
	while(t--){
	ll n;
	cin>>n;
	ll x[n];
	
	for(ll i=0;i<n;i++){
		cin>>x[i];
	}
	ll res=0;
	ll co[60]={0};
	for(ll i=0;i<n;i++){
		for(ll j=0;j<60;j++){
			if((1ll<<j)&x[i])co[j]++;
			
		}
	}
	for(ll i=0;i<n;i++){
	ll r=0,s=0;
	for(ll j=0;j<60;j++){
	ll p=co[j];
	if((1ll<<j)&x[i]){
		r+=((1ll<<j)%mod)*n;
		s+=((1ll<<j)%mod)*p;
	}
	else{
		r+=((1ll<<j)%mod)*p;
	}
	r%=mod;
	s%=mod;
	}
	r*=s;
	r%=mod;
	res+=r;
	res%=mod;
	}
	res%=mod;
	cout<<res<<endl;
	}
}