
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define ll long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bs binary_search
#define mp make_pair
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define up upper_bound
#define ld long double
#define meme(a,no)  memset(a,no,sizeof(a))
#define all(v)  v.begin(),v.end()
 

using namespace std; 

const int INF=1e18;

const int N=200000+5;

const int mod=1e9+7;

int32_t main(){
  ios;
  int fact[N];
  fact[0]=1;
  fact[1]=1;
  for(int i=2;i<N;i++){
    fact[i]=((fact[i-1]%mod)*(i%mod))%mod;
  }
  int T;
  cin>>T;
  //T=1;
  while(T--){
    int n;
    cin>>n;
    int a[n];
    int i,j,k,l;
    map<int,int>m;
    int ans=0;
    for(i=0;i<n;i++){
      cin>>a[i];
      m[a[i]]++;
      if(i==0){
        ans=a[i];
      }
      else ans=ans&a[i];
      // cout<<i<<" "<<ans<<endl;
    }
    if(m[ans]<=1){
      cout<<0<<endl;
      continue;
    }
    int calc=0;
    calc=fact[n-2];
    calc=((calc%mod)*((m[ans]-1)%mod))%mod;
    calc=((calc%mod)*(m[ans]%mod))%mod;
    cout<<calc<<endl;
  }    
}