#include<bits/stdc++.h>
#define int         int64_t
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mi        map<int,int>
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a[500005], n, bit[61], OR[500005], AND[500005];
void solve(){
	cin>>n;
	memset(bit, 0, sizeof bit);
	int ans = 0;
	for(int i=1;i<=n;i++){
		OR[i] = AND[i] = 0;
		cin>>a[i];
		for(int j=0;j<=60;j++){
			bit[j]+=((a[i]>>j)&1);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=60;j++){
			int power = (1LL<<j)%hell;
			if((a[i]>>j)&1){
				OR[i]=(OR[i]+ power*n)%hell;
				AND[i]=(AND[i]+ power*bit[j])%hell;
			}else{
				OR[i] =(OR[i]+power*bit[j])%hell;
			}
		}
		ans = (ans+OR[i]*AND[i])%hell;
	}
	cout<<ans<<endl;
}

signed main(){
    ios
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif 
        
    int test=1;
    cin>>test;
    while(test--){
        solve();
    }    
    return 0;
}