#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll Mod = 1000000007;

int t;
int n;
ll x[500500];
ll sum_bit[70];

int main(){
	ios::sync_with_stdio(false);
	cin >> t;
	while(t--){
		cin >> n;
		rep(i, n) cin >> x[i];
		memset(sum_bit, 0, sizeof(sum_bit));
		rep(b, 60) rep(i, n) sum_bit[b] = (sum_bit[b] + (x[i] & (1LL << b))) % Mod;
		ll ans = 0;
		rep(j, n){
			ll sum_and = 0, sum_or = 0;
			rep(b, 60){
				if(x[j] & (1LL << b)) sum_and = (sum_and + sum_bit[b]) % Mod, sum_or = (sum_or + (1LL << b) % Mod * n % Mod) % Mod;
				else sum_or = (sum_or + sum_bit[b]) % Mod;
			}
			ans = (ans + sum_and * sum_or) % Mod;
		}
		cout << ans << endl;
	}
	return 0;
}
