#include #define MOD 1000000007 using namespace std; int T, n, a[200005], tot, mid, fac[200005], nev[200005], ans; int C(int x, int y) {return (int)(1LL * fac[x] * nev[y] % MOD * nev[x - y] % MOD);} int fpm(int x, int y) { int ret = 1; while (y) { if (y & 1) ret = 1LL * ret * x % MOD; x = 1LL * x * x % MOD; y >>= 1; } return ret; } int main() { fac[0] = nev[0] = 1; for (int i = 1; i <= 200000; i++) { fac[i] = 1LL * fac[i - 1] * i % MOD; nev[i] = fpm(fac[i], MOD - 2); } scanf("%d", &T); while (T--) { scanf("%d", &n); n *= 2; for (int i = 1; i <= n; i++) scanf("%d", a + i); ans = 1; for (int i = 1; i <= n; i++) { int j = i; while (j < n && a[j + 1] == a[i]) j++; tot = j - i + 1; mid = tot / 2; if (i % 2 == 0 && j % 2 == 1) ans = 1LL * ans * (C(tot, mid) + C(tot, mid + 1)) % MOD; else if (i % 2 == 1 && j % 2 == 1) ans = ans * 1LL * C(tot, mid) * 2 % MOD; else ans = 1LL * ans * C(tot, mid) % MOD; i = j; } printf("%d\n", ans); } }