#include const int MOD = 1e9 + 7; const int MAXN = 100005; int a[2 * MAXN], b[2 * MAXN], c[2 * MAXN]; long long fac[2 * MAXN], inv[2 * MAXN]; int n; int read() { int p = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') p = p * 10 + (c - '0'), c = getchar(); return p; } long long power(long long a, long long b) { long long c = 1; while(b) { if (b & 1) c = c * a % MOD; a = a * a % MOD; b >>= 1; } return c; } long long calc(int x, int y) { return (fac[x] * inv[y] % MOD) * inv[x - y] % MOD; } int main() { fac[0] = 1; for(int i = 1; i <= 200000; i++) fac[i] = fac[i - 1] * i % MOD; inv[200000] = power(fac[200000], MOD - 2); for(int i = 199999; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % MOD; int T; T = read(); while(T--) { n = read(); for(int i = 1; i <= 2 * n; i++) b[i] = c[i] = 0; long long ans = 1; for(int i = 1; i <= 2 * n; i++) { a[i] = read(); b[a[i]]++, c[a[i]] = i; if (i % 2 == 0) { if (a[i] != a[i - 1]) ans = ans * 2 % MOD; //printf("%d %d\n", i, ans); } } for(int i = 1; i <= 2 * n; i++) if (b[i] > 1) { if (b[i] & 1) { ans = ans * calc(b[i], b[i] / 2) % MOD; } else { if (c[i] & 1) { ans = ans * (calc(b[i], b[i] / 2) * inv[2] % MOD + calc(b[i], b[i] / 2 - 1) * inv[2] % MOD) % MOD; } else { ans = ans * calc(b[i], b[i] / 2) % MOD; } } } printf("%d\n", (int)ans); } return 0; }