#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const int rr = 233;
int T;
int n;
ll pre[maxn],a[maxn];
ll cal(ll cnt){
    return cnt * (cnt - 1) % mod;
}
int main (){
    scanf("%d",&T);
    pre[0] = 1;
    for(int i = 1; i <= 1e6; i ++) pre[i] = pre[i - 1] * i % mod;
    while(T--){
        scanf("%d",&n);
        int cnt = 0;
        for(int i = 1; i <= n; i ++){
            scanf("%lld",&a[i]);
        }
        ll ans = a[1];
        for(int i = 2; i <= n; i ++){
            ans = ans & a[i];
        }
        for(int i = 1; i <= n; i ++){
            if(a[i] == ans) cnt ++;
        }
        ll pr = cal(cnt) % mod * pre[n - 2] % mod;;
        printf ("%lld\n",pr);



    }






}
