/* author:  dharm veer sharma */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include<iomanip>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<climits>
#include<stack>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<string> vs;



#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define endl cout<<"\n"
#define all(v) v.begin() , v.end()
#define f(i,l,r) for(int i=l;i<r;i++)
#define fr(i,l,r) for(int i=r-1;i>=l;i--)

#define lps(v,x) (lower_bound(all(v),x)-v.begin())
#define ups(v,x) (upper_bound(all(v),x)-v.begin())

#define mem(a,x) memset(a , x , sizeof(a));

#define PI 3.1415926535897932384626
#define mod 1000000007
#define md 998244353
#define INF 1e18

#define mp make_pair
#define pb push_back
#define F first
#define S second

/* -------------------> | ------------------> | -----------------> | --------------------> | -----------------> */

// prime number upto 500..
ll prr[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
    43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 
    103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157,
    163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
    227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 
    281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 
    353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
    421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499};


//function to calculate a^b under mod...
ll powmod(ll a,ll b, ll modulo){
    
    if(b==0 || a==1) return 1;
    ll half=powmod(a,(b/2),modulo) % modulo;
    ll full = (half*half)%modulo;

    if(b%2) return (full*a)%modulo;
    return full%modulo;
}


//function to calculate inverse modulo under mod...assuming gcd is 1
ll invmod(ll a,ll modulo){
    ll check=powmod(a,modulo-2,modulo) %modulo;
    return check;
}

//to calculate gcd..
ll gcd(ll a,ll b){
	if (b==0) return a;
	return gcd(b,a%b);
}

//to calculate lcm..
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

// prime sieve..

bool isPrime[5000005];
int prime[5000005];
void sieve(ll N) {
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers..
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
        
        int j = 0;
        for(int i = 2;i<=N;i++)
        {
            if(isPrime[i])
            {
                prime[j] = i;
                j++;
            }
        }
    }


// check palindromic string..
bool palindrome(string s){
    for(ll i = 0;i<s.length()/2;i++)
    {
        if(s[i]!=s[s.length()-i-1]) return 0;

    }
    return 1;
}
/* <------------------- | <------------------ | <----------------- | <-------------------- | <----------------- */

ll res[200002];
void fact()
{
    ll prod = 1;
    res[0] = 1;
    for(int i = 1 ; i < 200002 ; i++)
    res[i] = (1LL*res[i-1]*i)%mod , res[i] %= mod;
}
void solve()
{
    int n;
    cin >> n;
    
    int arr[n];
    f(i,0,n)
    cin >> arr[i];
    
    int temp = arr[0];
    
    f(i,1,n)
    temp &= arr[i];
    
    map<int,int> mp;
    
    for(int i : arr)
    mp[i]++;
    
    ll ans = 0;
    
    for(int i = 0 ; i < n ; i++)
    {
        ll x = 1;
        if(mp[arr[i]] > 1 && arr[i] == temp)
        {
            x = (1LL*x*(1LL*mp[arr[i]]*(mp[arr[i]] - 1))%mod)%mod;
            ans = (ans%mod + (1LL*x*res[n-2])%mod)%mod;
            mp.erase(arr[i]);
        }
    }
    
    ans %= mod;
    
    cout<<ans<<"\n";
    
    
    
}

int main()
{
    
    clock_t start , end;
    start = clock();
    
    fact();
    //sieve(5000005);
    fast;  // fast input/output..
    int t = 1;
    cin>>t;
    while(t--){
        solve();
    }
    
    
    
    end = clock();
    double time = double(end - start)/(double)(CLOCKS_PER_SEC);
    //cout<<time<<"\n";
    
    return 0;
}
