#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &e : a) {
		cin >> e;
	}

	int x = *min_element(a.begin(), a.end());
	int ct = 0;

	for (int i = 0; i < n; i++) {
		if ((x & a[i]) != x) {
			cout << "0\n";
			return;
		}
		if (a[i] == x)
			ct++;
	}

	int ans = ct * (ct - 1);

	for (int i = 1; i <= n - 2; i++) {
		ans = (ans * i) % M;
	}

	cout << ans << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(12);

	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}