#include<bits/stdc++.h>
using namespace std;
#define M 500000
typedef long long ll;
typedef unsigned long long ull;
inline ll read() {
	char ch;
	ll f = 1, res = 0;
	while ((ch = getchar()) < '0' || ch > '9')
		if (ch == '-') f = -1;
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + (ch ^ 48);
		ch = getchar();
	}
	return f * res;
}
inline void pt(ll u,ll mod) {
	printf("%lld", u);
	if (mod == 1)
		putchar(' ');
	else if (mod == 2)
		putchar('\n');
}
ll mod=1e9+7;
ll arr[M];
ll p[M];
int main() {
	//freopen("../in", "r", stdin);
	//freopen("../out", "w", stdout);
	p[1]=1;
	p[0]=1;
	for(ll i=2;i<M;i++)
		p[i]=p[i-1]*i%mod;
	ll q = read();
	while (q--) {
		ll n = read();
		ll k = pow(2, 40) + 0.1 - 1;
		for (ll i = 0; i < n; i++) {
			ll t = read();
			arr[i] = t;
			k &= t;
		}
		ll cnt = 0;
		for (ll i = 0; i < n; i++) {
			if (arr[i] == k)
				cnt++;
		}
		ll ans = cnt * (cnt - 1) % mod;
		pt(ans * p[n - 2] % mod, 2);
	}
	return 0;
}