#include using namespace std; #define ll long long const int N = 200005, P = 1000000007; int T, n, fac[N], ifac[N]; int Pow(ll x, int y=P-2){ int ans=1; for(; y; y>>=1, x=x*x%P) if(y&1) ans=ans*x%P; return ans; } int main() { fac[0]=1; for(int i=1; i<=200000; ++i) fac[i]=(ll)fac[i-1]*i%P; ifac[200000]=Pow(fac[200000]); for(int i=200000; i; --i) ifac[i-1]=(ll)ifac[i]*i%P; scanf("%d", &T); while(T--){ scanf("%d", &n); int ans=1; for(int i=1, last=0, cnt=0; i<=(n<<1|1); ++i){ int x=0; if(i<=n<<1) scanf("%d", &x); if(x==last) ++cnt; else{ if((i-cnt)&1){ if(cnt&1) ans=(ll)ans*fac[cnt]%P*ifac[cnt/2]%P*ifac[cnt/2+1]%P; else ans=(ll)ans*fac[cnt]%P*ifac[cnt/2]%P*ifac[cnt/2]%P; } else{ if(cnt&1) ans=2ll*fac[cnt]*ifac[cnt/2]%P*ifac[cnt/2+1]%P*ans%P; else ans=((ll)fac[cnt]*ifac[cnt/2]%P*ifac[cnt/2]+(ll)fac[cnt]*ifac[cnt/2-1]%P*ifac[cnt/2+1])%P*ans%P; } cnt=1, last=x; } } printf("%d\n", ans); } return 0; }