#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;

    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vector<int>vec(n);

        for(int i =0 ; i < n; i++ ) cin>>vec[i];
        int xx = vec[0];
        for(auto x : vec) xx &= x;
        for(auto &x: vec) x ^= xx;
        ll zero = 0;
        for(auto x : vec) zero += (x == 0);
        ll baki = n - zero;

        ll ans = ( zero * (zero-1) ) %MOD;
        baki += zero - 2;

        for(ll i = 1 ; i <= baki ; i++) {
            ans *= i;
            ans %= MOD;
        }

        cout<<ans<<'\n';
    }
    return 0;
}