#pragma GCC optimize("Ofast")
#pragma loop_opt(on)

#include<bits/stdc++.h>

#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define all(x) (x).begin(),(x).end()
#define mem(x,i) memset((x),(i),sizeof((x)))

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ld = long double;

const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);

#define Bint __int128
#define int long long
int qpow(int x,int powcnt,int tomod){
	int res = 1;
	for(;powcnt;powcnt>>=1,x=(x*x)%tomod)
		if(1&powcnt)res = (res*x)%tomod;
	return (res%tomod);
}
int inv(int x){ return qpow(x,mod-2,mod); }
// --------------------------------------**
const int N = 5e5+10;

int n;
int a[N];
int sum[63];

void solve(){
	cin >> n;
	mem(sum,0);
	for(int i=0;i<n;i++){
		cin >> a[i];
		int c = 0,x = a[i];
		while(x){
			if(x&1)
				sum[c]++;
			c++;
			x >>= 1;
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		int ss = 0,pp = 0;
		int x = a[i];
		for(int j=0;j<61;j++,x>>=1){
			if(x&1){
				int tmp = n*((1LL<<j)%mod)%mod;
				ss = (ss+tmp)%mod;
				tmp = sum[j]*((1LL<<j)%mod)%mod;
				pp = (pp+tmp)%mod;
			}
			else{
				int tmp = sum[j]*((1LL<<j)%mod)%mod;
				ss = (ss+tmp)%mod;
			}
		}
		ans = (ans+(ss*pp%mod))%mod;
	}
	cout << ans << '\n';
}

signed main(){
    Rushia_mywife
    int t = 1; 
    cin >> t;
    while(t--)
        solve();
}
