#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
using namespace std;



///geeks for geeks

// C++ program to answer queries
// of nCr in O(1) time.
#include <bits/stdc++.h>
#define ll long long
const int N = 200010;
using namespace std;

// array to store inverse of 1 to N
ll factorialNumInverse[N + 1];

// array to precompute inverse of 1! to N!
ll naturalNumInverse[N + 1];

// array to store factorial of first N numbers
ll fact[N + 1];

// Function to precompute inverse of numbers
void InverseofNumber(ll p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (int i = 2; i <= N; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
// Function to precompute inverse of factorials
void InverseofFactorial(ll p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    // precompute inverse of natural numbers
    for (int i = 2; i <= N; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}

// Function to calculate factorial of 1 to N
void factorial(ll p)
{
    fact[0] = 1;

    // precompute factorials
    for (int i = 1; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}

// Function to return nCr % p in O(1) time
ll Binomial(ll N, ll R, ll p)
{
    // n C r = n!*inverse(r!)*inverse((n-r)!)
    ll ans = ((fact[N] * factorialNumInverse[R])
              % p * factorialNumInverse[N - R])
             % p;
    return ans;
}

// Driver Code

int main()
{
    ll a,b,c,d,e,i;
     ll p = 1000000007;
    InverseofNumber(p);
    InverseofFactorial(p);
    factorial(p);
    //cin >> a;
    scanf("%lld",&a);
    while(a--)
    {
        //cin >> b;
        scanf("%lld",&b);
        map<ll,ll>mp;
       vector<ll>vec;
       ll left[b+10],right[b+10];
        while(b--)
        {
            //cin >> d;
            scanf("%lld",&d);
            mp[d]++;
            vec.push_back(d);
        }

        //cout << "left  " << endl;
        for(i=0;i<vec.size();i++)
        {
            if(i==0)
            {
                left[i]=vec[i];
            }
            else{
                left[i]=left[i-1]&vec[i];
            }
           // cout << left[i] << endl;
        }
        ///right
        //cout << "right " << endl;
        for(i=vec.size()-1;i>=0;i--)
        {
            if(i==vec.size()-1)
            {
                right[i]=vec[i];
            }
            else{
                right[i]=right[i+1]&vec[i];
            }
            //cout << right[i] << endl;
        }
        ll ans=0;
        ll cnt=vec.size()-2;
        if(vec.size()==2)
        {
            if(mp[vec[0]]==2)
            {
               ans=2;
            }
            else{
                ans=0;
            }
        }
        else{
                set<ll>st;
           for(i=0;i<vec.size();i++){
               if(st.count(vec[i]))
               continue;
                st.insert(vec[i]);


           if(mp[vec[i]]>1)
           {
               ll x=0;


               if(i-1>=0 && i+1<vec.size())
               {
                   x=left[i-1]&right[i+1];
               }
               else if(i-1>=0)
               {
                   x=left[i-1];
               }
               else{
                x=right[i+1];
               }

               if(x==vec[i])
               {
                   //cout << "ncr" << mp[vec[i]] << " " << 2 << " " << ":DDD " << (ll)nCrModPFermat(mp[vec[i]],2, p) << endl;
                ans=(ans%p)+ ((((Binomial(mp[vec[i]],2, p)*2)%p)*(fact[cnt]%p))%p);
                ans%=p;

               }
           }

        }



        }
        printf("%lld\n",ans);
        //cout << ans << endl;




    }


}


