#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define dingyi int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1
#define y0 y_csyakioi_0
#define y1 y_csyakioi_1
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define per(i, x, y) for(int i = y; i >= x; --i)
#define repg(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define mpr make_pair
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ x = x * 10 + (ch ^ 48); ch = getchar(); }
	return x * f;
}
const int N = 200010, mod = 1000000007;
int n, a[N], ans, cnt, minx;
inline void mian(){
	n = read(); rep(i, 1, n){
		a[i] = read();
	}
	minx = a[1];
	rep(i, 2, n) minx &= a[i];
	cnt = 0;
	rep(i, 1, n) if(a[i] == minx) ++cnt;
	cnt = 1ll * cnt * (cnt - 1) % mod;
	rep(i, 1, n - 2) cnt = 1ll * cnt * i % mod;
	printf("%d\n", cnt);
}
int main(){ int qwq = read(); while(qwq--) mian(); return 0; }