Can someone please help me, I got TLE on O(N) on 714B?
mod = 10**9 + 7
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
count = arr[0]
f = 1
for i in range(1,n):
count&=arr[i]
f*=i
f//=(n-1)
t = arr.count(count)
p = 1
if(t<=1):
print(0)
else:
p = t*(t-1)
re = p*f
print(re%mod)