#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename T>
inline void read(T &f) {
    f = 0; T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}
const ll N=2e6+100,mod=1e9+7,inf=0x3f3f3f;
ll t;
ll a[N];
ll A(ll n,ll m) {
	ll res=1;
	for(ll i=m-n+1; i<=m; i++)res=res*i%mod;
	return res;
}
signed main() {
//	cout<<min(inf,1000000000ll)<<endl; 
	read(t);
	while(t--) {
		ll n;
		read(n);
		ll minn=inf;
		map<ll,ll>mp;
		ll jishu=0;ll mx;
		for(ll i=1; i<=n; i++) {
			int a;read(a);
			if(i==1)mx=a;
			else mx=mx&a;
			mp[a]++;
		}
//		cout<<zui<<" "<<mp[zui]<<endl;
		if(mp[mx]>=2){
			ll res=1;
			res*=A(n-2,n-2)%mod;
			res%=mod;
			res*=A(2,mp[mx])%mod;
			res%=mod;
			print(res%mod,'\n');
		}else print(0,'\n');
	}
}
