//------HARSH------//
#include<bits/stdc++.h> 
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

#define int long long 
#define f(i,a,n) for(int i=a;i<n;i++)
#define rf(i,a,n) for(int i=n-1;i>=a;i--)
#define read(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define in cin>>
#define out cout<<
#define fr first
#define sc second
#define VC vector<int>
#define VP vector<pair<int,int>>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832

int gcd(int a, int b){
    if (b == 0){return a;}
    else{return gcd(b,a%b);}
}

int lcm(int a, int b){
    return (a*b)/(gcd(a,b));
}

const int MOD=1e9+7;
vector<int> fact(200001,1);

void solve(){
    int n;
    cin>>n;

    int arr[n];
    read(arr,n);
    map<int,int> vec;
    int AND=arr[0];

    vec[arr[0]]++;
    
    f(i,1,n){
        vec[arr[i]]++;
        AND&=arr[i];
    }

    if(vec[AND]<2){cout<<"0\n";return;}

    int temp=(vec[AND]*(vec[AND]-1)/2)%MOD;

    int ans=(fact[n-2]*temp*2)%MOD;

    cout<<ans<<"\n";
}


int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin.tie(0);
    cout.tie(0);
    
    for(int i=1;i<200001;i++){
        fact[i]=(i)*fact[i-1];
        fact[i]%=MOD;
    }

    int t;
    t=1;
    in t;
    while(t--){
        solve();  
    }    
}