#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef long long ll;
using namespace std;
#define V vector<ll>
#define VV vector<vector<ll>>
#define A(a) for(auto &x:a)cin>>x;
#define C(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define F(n) for(int i=0;i<n;i++)
#define Q int tt,qq; cin>>tt ;for(qq=1;qq<=tt;qq++)
#define I ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define B(a) a.begin(),a.end()
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
ll M=1000000007,inf=9223372036854775807,N=100010;
int main()
{
	I
	Q
	{
		ll n,i,j;
		cin>>n;
		bool a[n][65];
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++){
			ll x;
			cin>>x;
			for(j=0;x && j<64;j++){
				a[i][j]=x&1;
				x/=2;
			}
		}
		ll ans=0;
		V b(64);
		for(i=0;i<64;i++){
			ll x=0;
			for(j=0;j<n;j++){
				x+=a[j][i];
			}
			b[i]=x;
		}
		for(i=0;i<n;i++){
			ll x=0,y=0,t=1;
			for(j=0;j<64;j++){
				if(a[i][j]){
					x+=b[j]*t;
					y+=n*t;
				}
				else y+=b[j]*t;
				t*=2;
				x%=M;
				y%=M;
				t%=M;
			}
			ans+=(x*y)%M;
			ans%=M;
		}
		cout<<ans<<endl;
	}
}