#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pp;

ll big=1000000007;

ll fac(ll x)
{
    ll ans=1;
    for(ll i=2;i<=x;i++) ans=(ans*i)%big;
    return ans;
}



int main()
{
    int t,n;
    ll band,a[200010];
    ll co;
    cin >> t;
    while(t--)
    {
        cin >> n;
        cin >> band;
        a[0]=band;
        co=0;
        for(int i=1;i<n;i++)
        {
            cin >> a[i];
            band=band&a[i];
        }
        for(int i=0;i<n;i++)
        {
            if(a[i]==band) co++;
        }
        printf("%lld\n",(((co*(co-1))%big)*fac(n-2))%big);
    }
}
