#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int mod=1e9+7;
const int maxV=2e5+1;
const ll inf=1e18+1;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<ll> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        ll andVal=a[0];
        for(int i=0;i<n;i++){
            andVal=(andVal)&(a[i]);
        }
        ll cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]==andVal){
                cnt++;
            }
        }
        ll ans=(cnt*(cnt-1))%mod;
        for(ll i=1;i<=n-2;i++){
            ans=(ans*i)%mod;
        }
        ans=(ans%mod+mod)%mod;
        cout<<ans<<"\n";
    }
}