#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);

using namespace std;

const int mod = 1e9 + 7;
const int N = 2e5 + 10;

struct Mint {
    ll v; explicit operator ll() const { return v; }
    Mint() { v = 0; }
    Mint(ll _v) { 
        v = (-mod < _v && _v < mod) ? _v : _v % mod;
        if (v < 0) v += mod;
    }
    friend bool operator==(const Mint& a, const Mint& b) { return a.v == b.v; }
    friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
    friend bool operator<(const Mint& a, const Mint& b) { return a.v < b.v; }
   
    Mint& operator+=(const Mint& m) { if ((v += m.v) >= mod) v -= mod; return *this; }
    Mint& operator-=(const Mint& m) { if ((v -= m.v) < 0) v += mod; return *this; }
    Mint& operator*=(const Mint& m) { v = v*m.v%mod; return *this; }
    Mint& operator/=(const Mint& m) { return (*this) *= inv(m); }
    Mint& operator^=(const ll& e) { return (*this) = pow(*this, e); }

    friend Mint pow(Mint a, ll p) {
        Mint ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans;
    }
    
    friend Mint inv(const Mint& a) { assert(a.v != 0); return pow(a, mod-2); }

    Mint operator-() const { return Mint(-v); }
    Mint& operator++() { return *this += 1; }
    Mint& operator--() { return *this -= 1; }
    Mint operator++(int) { Mint temp; temp.v = v++; return temp; }
    Mint operator--(int) { Mint temp; temp.v = v--; return temp; }

    friend Mint operator+(Mint a, const Mint& b) { return a += b; }
    friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
    friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
    friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
    friend Mint operator^(Mint a, const ll& e) { return a ^= e; }

    friend ostream& operator<<(ostream& os, const Mint& m) {
        os << m.v; return os;
    }

    friend istream& operator>>(istream& is, Mint& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};

Mint fact[N];

void pre() {
    fact[0] = Mint(1);
    for (int i = 1; i < N; i++) fact[i] = Mint(i) * fact[i - 1];
}

Mint ncr(int n, int r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] / (fact[n - r] * fact[r]);
}

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];

    sort(arr.begin(), arr.end());
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if ((arr[i] & arr[0]) != arr[0]) {
            cout << 0 << "\n"; return;
        }
    }
    for (int i = 0; i < n; i++) if (arr[i] == arr[0]) cnt++;

    cout << ncr(cnt, 2) * 2 * fact[n - 2] << "\n";
}

int main() {
    FASTIO;
    PRECISION;

    pre();

    int t = 1;
    cin >> t;

    for (int i = 1; i <= t; i++) {
        solve();
    }
}