#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fp(db) fixed<<setprecision(10)<<db
#define all(x) x.begin(),x.end()
#define cflush(x) cout<<x<<endl; fflush(stdout)


const int N=2e6+5;
const int mod=1e9+7;

int main(){
    cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vi res(n);
        int cBit=(1<<30)-1;
        for(int i=0;i<n;i++) {
            cin>>res[i];
            cBit&=res[i];
        }
        int c0=0;
        for(int i=0;i<n;i++) {
            if(res[i]&(~cBit));
            else c0++;
        }
        int f=1;
        for(int i=1;i<=n-2;i++) f=(1LL*f*(i))%mod;
        ll ans=(1LL*c0*(c0-1))%mod;
        ans = (ans*f)%mod;
        cout<<ans<<"\n";
    }
    return 0;
}