cin >> n; for (int i = 1; i < n; ++i) { int len, x, y; cin >> len; for (int j = 1; j <= len; ++j) cin >> x >> y, a[i].emplace_back(x, y); } int M = (1 << n - 1) - 1; ll ans = 0; for (int S = 0; S <= M; ++S) { for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) g[i][j] = 0; for (int o = 1; o < n; ++o) if (S >> o - 1 & 1) for (auto [x, y] : a[o]) --g[x][y], --g[y][x], ++g[x][x], ++g[y][y]; int cnt = __builtin_popcount(S); ll res = Gauss(n - 1); if (n - 1 - cnt & 1) ans = (ans - res) % p; else ans = (ans + res) % p; } cout << (ans + p) % p << "\n"; return0; }