#include<bits/stdc++.h>
#define ll long long
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;
string s1, s2, s3;
const ll MAXN = 17179869184;//11λ
const ll MOD = 1e9 + 7; //11λ

int main()
{
    FAST_IO;
    cin >> k;

    while ( k-- )
    {
        cin >> n;
        map<ll, ll>mm;

        for ( i = 0, t = MAXN - 1; i < n; i++ ) cin >> j, mm[j]++, t &= j;

        sum = mm[t] * ( mm[t] - 1 ) % MOD;

        for ( i = 2; i <= n - 2; i++ ) sum = sum * i % MOD;

        cout << sum << endl;
    }

}






