#include using namespace std; #define ll long long const int mod = 1000000007; int a[200020],fac[200020],ifac[200020]; int dp[200020][3]; int qpow(int a,int n) { int ans=1; for (;n;n>>=1,a=(ll)a*a%mod) if (n&1) ans=(ll)ans*a%mod; return ans; } inline int C(int n,int k) { return fac[n]*(ll)ifac[k]%mod*ifac[n-k]%mod; } int main(void) { // freopen("d.in","r",stdin); int N=200005; fac[0]=1; for (int i=1;i<=N;i++) fac[i]=fac[i-1]*(ll)i%mod; ifac[N]=qpow(fac[N],mod-2); for (int i=N-1;i>=0;i--) ifac[i]=ifac[i+1]*(ll)(i+1)%mod; // for (int i=0;i<=10;i++) printf("%d %d %lld\n",fac[i],ifac[i],(ll)fac[i]*ifac[i]%mod); int T; scanf("%d",&T); while (T--) { int n; scanf("%d",&n); // printf(" -------------- N = %d -------- \n",n); for (int i=1;i<=2*n;i++) { scanf("%d",&a[i]); } dp[0][0]=1,dp[0][1]=dp[0][2]=0; int s=0, pre=0; for (int i=1;i<=2*n+1;i++) { if (i <= 2*n && (i==1 || a[i]==a[i-1])) s++; else { if (s % 2 == 1) { if (i % 2 == 0) { dp[pre+1][0] = 0; dp[pre+1][1] = dp[pre][0]*(ll)C(s,s/2)%mod; dp[pre+1][2] = dp[pre][0]*(ll)C(s,s/2)%mod; } else { dp[pre+1][0] = (dp[pre][1]+dp[pre][2])*(ll)C(s,s/2)%mod; dp[pre+1][1] = 0; dp[pre+1][2] = 0; } } else { if (i % 2 == 1) { dp[pre+1][0] = dp[pre][0]*(ll)C(s,s/2)%mod; dp[pre+1][1]=dp[pre+1][2]=0; } else { dp[pre+1][0] = 0; dp[pre+1][1] = (dp[pre][1]*(ll)C(s,s/2) + dp[pre][2]*(ll)C(s,s/2-1))%mod; dp[pre+1][2] = (dp[pre][2]*(ll)C(s,s/2) + dp[pre][1]*(ll)C(s,s/2-1))%mod; } } pre++; // printf("s = %d, i = %d, %d %d %d\n",s,i,dp[pre][0],dp[pre][1],dp[pre][2]); s=1; } } int ans = dp[pre][0]; printf("%d\n", ans); } return 0; }