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

int mod = 1e9+7;
ll fat[200005];

int main(){

    fat[0] = 1;
    for(int i = 1; i <= 2e5; i++)
        fat[i] = fat[i-1] * i % mod;

    cout.sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;

        map<int,int> mapa;
        vector<int> v(n);
        for(int i = 0; i < n; i++){
            int x; cin >> x;
            v[i] = x;
            mapa[x]++;
        }
        sort(v.begin(), v.end());
        int aux = 0;
        for(int i = 0; i < n; i++)
            if( (v[0]&v[i]) == v[0])
                aux++;
        int cnt = 0;
        for(auto par : mapa){
            cnt = par.second;
            break;
        }
        if(cnt < 2 || aux != n){
            cout << 0 << endl;
            continue;
        }
        ll res = 1LL * cnt * (cnt - 1) % mod;
        res = res * fat[n-2] % mod;
        cout << res << endl;
    }

	return 0;
}