#include<bits/stdc++.h>
using namespace std;


int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int i,j,k,l,m,n,c1=0,c2=0,ans=0,res=0;
        map<long long int,long long int>mp,mp1;
        vector<long long int>v,v1,v2;
        set<long long int>st,st1;
        vector<pair<long long int,long long int>>vp,vp1;
        cin>>n;
        long long int arr1[n];
        for(i=0;i<n;i++)cin>>arr1[i];
        m=*min_element(arr1,arr1+n);
        for(i=0;i<n;i++)
        {
            if(arr1[i]==m)c1++;
            if((arr1[i]&m)!=m)c2++;
        }
        if(c1<2||c2!=0)cout<<0<<endl;
        else
        {ans=c1*(c1-1);
        for(i=n-2;i>=1;i--)
        ans=(ans*i)%1000000007;
        cout<<ans<<endl;
        }
    }
}