#include using namespace std; typedef long long ll; #define ri register int const int M=1000000007; int n,t,i,a[200005],j,k,b[200005],u; ll ans,p[200005],inv[200005],f[200005]; inline int read() { char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } ll qpow(ll a,ll b) { ll s=a,ans=1; while(b) { if(b&1) ans=ans*s%M; s=s*s%M; b>>=1; } return ans; } ll C(int a,int b) { return p[a]*inv[b]%M*inv[a-b]%M; } int main() { t=read(); p[0]=inv[0]=1; for(i=1;i<=200000;i++) { inv[i]=inv[i-1]*qpow(i,M-2)%M; p[i]=p[i-1]*i%M; } while(t--) { n=read(); for(i=1;i<=n*2;i++) a[i]=read(); u=0; for(i=1;i<=n*2;) { for(j=i;j<=n*2&&a[i]==a[j];j++); b[++u]=j-i; i=j; } ans=1; for(i=1;i<=u;i++) { int s=0; for(j=i;j<=u;j++) { s+=b[j]; if(s%2==0) break; } if(i==j) ans=ans*C(b[i],b[i]/2)%M; else { f[i]=C(b[i],b[i]/2); for(k=i+1;k