#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define mod 1000000007
vector<ll> fact(4e5);

void factorial(){
    fact[0] = 1;
	for(int i = 1; i < 4e5; i++){
		fact[i] = (fact[i-1] * i)%mod;
	}
}
int main(){
    int t;
    cin>>t;
    int p=t;
    factorial();
    while(t--){
        int n;
        cin>>n;
        int a[n];
        int ans=1;
        map<int,int>m;
        for(int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;
        }
        ans=a[0];
        for(int i=1;i<n;i++){
            ans=ans&a[i];
        }
        if(m[ans]<2){
            cout<<0<<endl;
        }
        else{
            ll cnt=m[ans];
            ll sum=(cnt*fact[n-2])%mod;
            sum=(sum*(cnt-1))%mod;

            cout<<sum<<endl;
        }
    }
}
