#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

///////////////////////////////////////////////////

const int MAX = 5e5 + 41;
const int MOD = 1e9 + 7;
const int B = 61;

int n;
ll a[MAX];
int q[B];
int p2[B];

bool bit(ll m, int i) {
	return (1LL & (m >> i));
}

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mul(int a, int b) {
	return (ll) a * b % MOD;
}

int ans[MAX];
int f[MAX];

void solve () {
	memset(q, 0, sizeof(q));
	fi(1, n) ans[i] = 0;
	p2[0] = 1;
	fi(1, B - 1) p2[i] = add(p2[i - 1], p2[i - 1]);

	fi(1, n) fj(0, B - 1) {
		if (bit(a[i], j)) {
			q[j]++;
		}
	}

	fi(1, n) {
		f[i] = 0;
		fj(0, B - 1) {
			if (bit(a[i], j)) continue;
			f[i] = add(f[i], mul(q[j], p2[j]));
		}
	}

	fi(1, n) fj(0, B - 1) if (bit(a[i], j)) {
		int v1 = q[j];
		int v2 = p2[j];
		int v3 = mul(n, (int) (a[i] % MOD));
		ans[i] = add(ans[i], mul(v1, mul(v2, v3)));
		ans[i] = add(ans[i], mul(v1, mul(v2, f[i])));
	}

	int answer = 0;
	fi(1, n) answer = add(answer, ans[i]);
	printf("%d\n", answer);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif
	
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		fi(1, n) scanf("%lld", &a[i]);
		solve();
	}

	exit();
	return 0;
}



