#include #include #include #include using namespace std; #define ll long long #define P 1000000007 #define N 200005 int n,m,k,l,T,s,p; int a[N],b[N]; ll jie[N],ans,inv[N]; ll f[N][3]; ll C(int n,int m){ return jie[n]*inv[m]%P*inv[n-m]%P; } int main(){ jie[0]=1; for (int i=1;i<=200000;i++)jie[i]=jie[i-1]*i%P; inv[0]=inv[1]=1; for (int i=2;i<=200000;i++)inv[i]=inv[P%i]*(P-P/i)%P; for (int i=2;i<=200000;i++)inv[i]=inv[i-1]*inv[i]%P; scanf("%d",&T); while(T--){ s=m=0; scanf("%d",&n); for (int i=1;i<=2*n;i++)scanf("%d",&a[i]); for (int i=1;i<=2*n;i++){ s++; if(a[i]!=a[i+1]||i==2*n)b[++m]=s,s=0; } ans=1; p=0; f[0][0]=1; for (int i=1;i<=m;i++){ if(p==0){ if((b[i]&1)==0)f[i][0]=f[i-1][0]*C(b[i],b[i]/2)%P; else{ p=1; f[i][1]=f[i][2]=f[i-1][0]*C(b[i],b[i]/2)%P; } continue; } if(p==1)if((b[i]&1)==0){ f[i][1]=(f[i-1][1]*C(b[i],b[i]/2)+f[i-1][2]*C(b[i],b[i]/2-1))%P; f[i][2]=(f[i-1][2]*C(b[i],b[i]/2)+f[i-1][1]*C(b[i],b[i]/2-1))%P; }else{ p=0; f[i][0]=(f[i-1][1]+f[i-1][2])*C(b[i],b[i]/2)%P; } } printf("%d\n",f[m][0]); } }