#include using namespace std; const int maxn = 2e6+233; typedef long long LL; const LL mod = 1e9+7; LL T,n,m,c,ok,tmp,add,ret,ans,sum,tot; LL arr[maxn],fac[maxn],fac2[maxn]; LL qpow(LL a, LL n)//计算a^n % mod { LL ans = 1; while(n) { if(n & 1)//判断n的最后一位是否为1 ans = (ans * a) % mod; n >>= 1;//舍去n的最后一位 a = (a * a) % mod;//将a平方 } return ans % mod; } LL comF(LL a,LL b) { return ((fac[a]*fac2[b]%mod)*(fac2[a-b])%mod); } void init() { fac[0]=1; for(LL i=1; i<=200000; ++i) { fac[i]=(fac[i-1]*i)%mod; } fac2[200000]=qpow(fac[200000],mod-2); for(int i=199999; i>=0; --i) fac2[i]=(fac2[i+1]*(i+1))%mod; } LL cal(LL x,LL y) { return comF(x,y)%mod; } LL solve() { ans=1; tot=1; tmp=0; LL i; for(i=2; i<=n*2; ++i) { if(arr[i]!=arr[i-1]) { if(tmp==1) { if(i%2==0) { ans=(ans*(cal(tot,tot/2)+cal(tot,tot/2+1)))%mod; } else { ans=(ans*cal(tot,tot/2))%mod; } } else { if(tot%2) ans=(ans*(cal(tot,tot/2)+cal(tot,tot-tot/2)))%mod; else ans=(ans*cal(tot,tot/2))%mod; } if(i%2==0) tmp=1; else tmp=0; tot=1; } else tot++; } if(tmp==1) { if(i%2==0) { ans=(ans*(cal(tot,tot/2)+cal(tot,tot/2+1)))%mod; } else { ans=(ans*cal(tot,tot/2))%mod; } } else { if(tot%2) ans=(ans*(cal(tot,tot/2)+cal(tot,tot-tot/2)))%mod; else ans=(ans*cal(tot,tot/2))%mod; } return ans; } int main() { // freopen("in.txt","r",stdin); init(); scanf("%I64d",&T); while(T--) { scanf("%I64d",&n); for(LL i=1; i<=n*2; ++i) { scanf("%I64d",&arr[i]); } ret = solve(); printf("%I64d\n",ret); } return 0; }