
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <iomanip>
#include <deque>
#include <set>
#include <queue>
#include <stack>
#include <sstream>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

#define MAX 200005
const int INF = 1e9;

int fac[MAX] = { 0 };
int mod = 1e9 + 7;

void initFac() {
	fac[0] = 1;
	for (int i = 1; i <= MAX; i++) {
		fac[i] = (1LL * i * fac[i - 1]) % mod;
	}
}

int bigMod(int a, int b, int mod) {
	int result = 1;
	a %= mod;
	while (b != 0) {
		if ((b & 1)) {
			result = (1LL * result * a) % mod;
		}
		b >>= 1;
		a = (1LL * a * a) % mod;
	}
	return result;
}

int inverseMod(int b, int m) {
	int res = bigMod(b, m - 2, m);
	if ((1LL * res * b) % mod == 1) {
		return res;
	}
	return -1;
}

int pombination(int n, int k, int mod) {
	int top = fac[n];
	int bot = fac[n - k];
	return (1LL * top * inverseMod(bot, mod)) % mod;
}

void testCase() {
	int n, a;
	cin >> n;
	unordered_map<int, int> map;
	for (int i = 0; i < n; i++) {
		cin >> a;
		map[a]++;
	}
	unordered_map<int, int>::iterator it, it2;
	int res = 0;
	bool flag;
	for (it = map.begin(); it != map.end(); it++) {
		if (it->second > 1) {
			flag = true;
			for (it2 = map.begin(); it2 != map.end(); it2++) {
				if (((it->first) & (it2->first)) != it->first) {
					flag = false;
					break;
				}
			}
			if (flag) {
				res = (res + 1LL * pombination(it->second, 2, mod) * fac[n - 2]) % mod;
			}
		}
	}
	cout << res << endl;
}

int main() {
	int t;
	cin >> t;
	initFac();
	for (int i = 1; i <= t; i++) {
		testCase();
	}
}