#include <bits/stdc++.h>

#define pb push_back
#define int long long 
#define debug(n) cerr << #n << " = " << n << '\n';

using namespace std;

const int MaxN = 1e6 + 10;
const int Mod = 1e9 + 7;
const int inf = 1e18;
int cnt[100] , a[MaxN];

void solve() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		for(int j = 0; j <= 60; j++) 
			if(a[i] & (1LL << j)) cnt[j]++;
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int x = 0 , y = 0;
		for(int j = 0; j <= 60; j++) {
			int p = (1LL << j) % Mod;
			if(a[i] & (1LL << j)) {
				x = (x + p * cnt[j]) % Mod;
				y = (y + p * n) % Mod;
			} else y = (y + p * cnt[j]) % Mod;
		}
		ans = (ans + x * y) % Mod;
	}
	cout << ans << '\n';
	fill(cnt , cnt + 100 , 0);
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	cin >> t;
	while(t--) 
		solve();
	return 0;
} 