#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
#include <list>
#include <map>
#include <set>
#include <limits>
#include <random>
#include <functional>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>

using namespace std;

const int N = 60;
const int M = 100010;
const int MOD = 1000000007;
const int INF = 1009000999;
const ll LINF = (1ll << 60) + 1337;
const ld EPS = 0.0000000001;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		vi cnt(N, 0);
		vl a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			for (int j = 0; j < N; j++) {
				if ((1ll << j) & a[i]) cnt[j]++;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int xand = 0;
			int xxor = 0;
			for (int j = 0; j < N; j++) {
				int mn = (1ll << j) % MOD;
				if (a[i] & (1ll << j)) {
					xand += (mn * 1ll * cnt[j]) % MOD;
					xand %= MOD;
					xxor += (mn * 1ll * n) % MOD;
					xxor %= MOD;
				}
				else {
					xxor += (mn * 1ll * cnt[j]) % MOD;
					xxor %= MOD;
				}
			}
			ans += (xand * 1ll * xxor) % MOD;
			ans %= MOD;
		}
		cout << ans << "\n";
	}
}

/*
	Important stuff
	- int overflow
	- array bounds
	- special cases (n=1, max n) maybe adhoc problem
	- doubles are read for a long time (4 * 10 ^ 5 danger GNU vs MS ICPC 2020 1/4)
	- don't get stuck on one approach
	- don't get stuck on one problem
	- recheck submissions if near the end of the tournament and there is nothing to do
	- do something instead of nothing and stay organized
*/