// Overidea
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repdo(i,l,r) for(int i=l;i>=r;--i)
#define ll long long
using namespace std;
//----------------------------------------------------
const int nsz=5e5+50;
const ll nmod=1e9+7;
ll t,n,li[nsz];
int cnt[100];
ll v1[nsz],v2[nsz];//or and
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin>>t;
	rep(cs,1,t){
		cin>>n;
		rep(i,1,n)cin>>li[i];
		rep(i,0,61)cnt[i]=0;
		rep(i,1,n)v1[i]=v2[i]=0;
		rep(b,0,61)rep(i,1,n)cnt[b]+=((li[i]>>b)&1);
		rep(i,1,n){
			rep(b,0,61){
				if((li[i]>>b)&1)v1[i]=(v1[i]+(1ll<<b)%nmod*n)%nmod;
				else v1[i]=(v1[i]+(1ll<<b)%nmod*cnt[b])%nmod;
				
				if((li[i]>>b)&1)v2[i]=(v2[i]+(1ll<<b)%nmod*(cnt[b]))%nmod;
			}
		}
		ll res=0;
		rep(i,1,n)res=(res+v1[i]*v2[i])%nmod;
		cout<<res<<'\n';
	}

	return 0;
}



