#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int MOD = 1e9 + 7;
int MAXN = 2e5 + 7;

int modmul(int a, int b) {
	return (ll) a * b % MOD;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;

	vector<int> fact(MAXN);
	fact[0] = fact[1] = 1;
	for (int i = 2; i < MAXN; i++) fact[i] = modmul(i, fact[i - 1]);

	while (t--) {
		int n;
		cin >> n;
		vector<int> arr(n);
		for (int i = 0; i < n; i++) cin >> arr[i];

		int mn = *min_element(arr.begin(), arr.end());
		int mncount = 0;
		for (auto i : arr) if (i == mn) mncount++;

		if (mncount <= 1) {cout << 0 << endl; continue;}

		int flag = 1;
		int alland = mn;
		for (auto i : arr) alland = (alland & i);

		if (alland != mn) {cout << 0 << endl; continue;}


		int ans = 0;
		ans = fact[n - 2];
		ans = modmul(ans, mncount);
		ans = modmul(ans, mncount - 1);

		cout << ans << endl;


	}

	return 0;
}