#include #include #include using namespace std; #define MOD 1000000007 long long frac[200010]; int T, N, ai, ans1, ans2, inv[200010]; long long C(int n, int m) { return frac[n] * inv[n - m] % MOD * inv[m] % MOD; } long long power(long long x, int y) { long long ans = 1; while (y) { if (y & 1) ans = ans * x % MOD; x = x * x % MOD; y /= 2; } return ans; } int main() { frac[0] = inv[0] = 1; for (int i = 1; i < 200010; ++i) { frac[i] = frac[i - 1] * i % MOD; inv[i] = power(frac[i], MOD - 2); } scanf("%d", &T); while (T--) { scanf("%d", &N); N = N * 2; ans1 = ans2 = 1; for (int i = 0, cnt = 0, last = 0; i <= N; ++i) { if (i < N) { scanf("%d", &ai); if (i == 1) last = ai; if (last == ai) ++cnt; } if (last != ai || i == N) { if (i % 2 == 0) if (cnt % 2 == 0) ans1 = ans1 * C(cnt, cnt / 2) % MOD; else ans1 = (ans1 * C(cnt, cnt / 2 + 1) % MOD + ans2 * C(cnt, cnt / 2) % MOD) % MOD; else if (cnt % 2 == 1) { ans2 = ans1 * C(cnt, cnt / 2 + 1) % MOD; ans1 = ans1 * C(cnt, cnt / 2) % MOD; } else { int t1 = ans1, t2 = ans2; ans1 = (t1 * C(cnt, cnt / 2) % MOD + t2 * C(cnt, cnt / 2 - 1) % MOD) % MOD; ans2 = (t1 * C(cnt, cnt / 2 + 1) % MOD + t2 * C(cnt, cnt / 2) % MOD) % MOD; } last = ai; cnt = 1; } } printf("%d\n", ans1); } return 0; }