#include #include #include #define F first #define S second using namespace std; typedef long long LL; typedef pair PLL; const LL MOD = 1e9 + 7; const int N = 2e5 + 10; int n; PLL a[N]; int ap; LL F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘 void init(){ inv[1] = 1; for(int i = 2; i < N; i ++){ inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD; } F[0] = Finv[0] = 1; for(int i = 1; i < N; i ++){ F[i] = F[i-1] * 1ll * i % MOD; Finv[i] = Finv[i-1] * 1ll * inv[i] % MOD; } } LL comb(int n, int m){//comb(n, m)就是C(n, m) if(m < 0 || m > n) return 0; return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD; } int main(){ init(); int T; scanf("%d", &T); while(T --){ scanf("%d", &n); int lst = -1, tmp; ap = 0; for(int i = 0; i < 2*n; ++ i){ scanf("%d", &tmp); if(tmp != lst){ a[ap ++] = PLL(tmp, 1); lst = tmp; } else{ ++ a[ap-1].S; } } int ls = 0; LL ans = 1; for(int i = 0; i < ap; ++ i){ if(ls == 0){ if(a[i].S & 1){ ans = ans * comb(a[i].S, a[i].S/2) * 2 % MOD; ls = 1; } else{ ans = ans * comb(a[i].S, a[i].S/2) % MOD; ls = 0; } } else{ if(a[i].S & 1){ ans = ans * comb(a[i].S, a[i].S/2) % MOD; ls = 0; } else{ ans = ans * (comb(a[i].S, a[i].S/2) + comb(a[i].S, a[i].S/2-1)) % MOD; ls = 1; } } } printf("%I64d\n", ans); } }