#include #include #include using namespace std; constexpr int Z = 998244353; using pii = pair; using vp = vector; using vi = vector; void dfs0(vp e[], int u, int p, int pord, vi dp[]) { dp[u].resize(e[u].size()); dp[u][0] = 1; for (int i = 1; i < (int)e[u].size(); i++) { int v = e[u][i].second; if (v == p) { e[p][pord].first = i; e[u][i].first = pord; } else { dfs0(e, v, u, i, dp); int ord = e[u][i].first, dv = e[v].size(); for (int j = 0; j < (int)e[v].size() - 1; j++) { dp[u][i] = 1ll * (dp[u][i] + dp[v][(ord-1-j+dv)%dv]) * (v + 1) % Z; } } } } void dfs1(vp e[], int u, int p, vi dp[], int ans[]) { int pre[e[u].size()]; int pu = 1; for (int i = 0; i < (int)e[u].size(); i++) { pre[i] = ((i == 0 ? 0 : pre[i-1]) + 1ll * pu * dp[u][i]) % Z; pu = 1ll * pu * (u + 1) % Z; } pu = 1; for (int i = (int)e[u].size() - 1; i >= 0; i--) { pre[i] = 1ll * pre[i] * pu % Z; pu = 1ll * pu * (u + 1) % Z; } int pos[e[u].size()+1]; for (int i = (int)e[u].size(); i >= 0; i--) { pos[i] = i == (int)e[u].size() ? 0 : 1ll * (pos[i+1] + dp[u][i]) * (u + 1) % Z; } ans[u] = pos[1]; for (int i = (int)e[u].size() - 1; i >= 1; i--) { auto [ord, v] = e[u][i]; if (v != p) { dp[v][ord] = (pos[i+1] + pre[i-1]) % Z; dfs1(e, v, u, dp, ans); } } } int main() { int n; cin >> n; vp e[n]; int e2[n-1]; fill(e2, e2 + n - 1, 0); for (int i = 0; i < n; i++) { int d; cin >> d; e[i].resize(d + 1); for (int j = 1; j <= d; j++) { cin >> e[i][j].first; e2[--e[i][j].first] ^= i; } } for (int i = 0; i < n; i++) { for (int j = 1; j < (int)e[i].size(); j++) { e[i][j].second = e2[e[i][j].first] ^ i; } } vi dp[n]; dfs0(e, 0, -1, -1, dp); int ans[n]; dfs1(e, 0, -1, dp, ans); for (int i = 0; i < n; i++) { cout << ans[i] << endl; } return 0; }