#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
void factorial(ll int *fact)
{
	fact[0]=1;
    for(ll int i=1;i<=200000;i++)
    {
    	fact[i]=(fact[i-1]*i)%mod;
	}
}
int main() 
{
  	int t=1;
  	cin>>t;
  	ll int fact[200001];
  	factorial(fact);
  	while(t--)
  	{
  		ll int n;
		cin>>n;
		ll int i,j,a[n];
		ll int mi=INT_MAX;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			mi=min(mi,a[i]);
		}
		ll int c=0;
		ll int an=mi;
		for(i=0;i<n;i++)
		{
			if(a[i]==mi)
			c++;
			an=an&a[i];
		}
		if(an!=mi && c>=2)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<((((((c*(c-1))/2)%mod)*fact[n-2])%mod)*2)%mod<<endl;
		}
	}
}