#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define me(a,x) memset(a,x,sizeof(a))
#define sf scanf
#define pf printf
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define gcd __gcd
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x) cout<<"x="<<x<<endl
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const ll llINF=9223372036854775807;
const int maxn=2e5+10;
const double pi=acos(-1.0);
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
using namespace std;
ll n,ans;
ll a[maxn];
void solve()
{
    sf("%lld",&n);
    rep(i,1,n){
        sf("%lld",&a[i]);
    }
    ll z=a[1]&a[2];
    rep(i,3,n){
        z=z&a[i];
    }
    ll sum=0;
    rep(i,1,n){
        if(a[i]==z) sum++;
    }
    ans=sum%mod*(sum-1)%mod;
    for(int i=n-2;i>=1;i--){
        ans=ans*i%mod;
    }
    pf("%lld\n",ans);
}

int main()
{
//    IOS;
    int _;
    sf("%d",&_);
    while(_--){
        solve();
    }
    return 0;
}
