#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, cnt = 0;
    cin >> n;
    long long a[n + 5];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long div = a[0], ans;
    for (int i = 1; i < n; i++) div = div & a[i];
    for (int i = 0; i < n; i++) {
      if (a[i] == div) cnt++;
    }
    if (cnt >= 2) {
      ans = cnt;
      if (cnt > 2) ans += cnt;
      for (long long i = 1; i < n - 1; i++)
        ans = (ans % 1000000007 * i % 1000000007) % 1000000007;
    } else
      ans = 0;
    cout << ans << endl;
  }
}
