#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
typedef priority_queue<ll, vector<ll>, greater<ll>> minheap;
typedef priority_queue<ll> maxheap;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 1e9 + 7, N = 2e5;
ll fact[N + 1];

void init(){
    fact[0] = fact[1] = 1;
    for(ll i = 2; i <= N; i++)
        fact[i] = (fact[i - 1]*i)%M;
}

void solve(){
    ll n;
    cin >> n;
    ll AND;
    ll arr[n];
    map<ll, ll> mp;
    for(ll i = 0; i < n; i++){
        cin >> arr[i];
        mp[arr[i]]++;
        if(i == 0)
            AND = arr[i];
        else
            AND = AND & arr[i];  
    }
    // if(mp.find(AND) == mp.end() || mp[AND] < 2){
    //     cout << 0 << "\n";
    //     return;
    // }
    ll ans = mp[AND]*(mp[AND] - 1)%M*fact[n - 2]%M;
    cout << ans << "\n";
}

int main()
{
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
     IOS
     int t = 1;
     cin >> t;
     init();
     while(t--){
        solve();
        // cout << fixed << setprecision(7); //For trailing 0's
     }
    return 0;
}