#include <bits/stdc++.h>   using namespace std;   ifstream in( in.txt );   ofstream out( out.txt );   long long a[1000006], b[1000006];   long long fortza(long long n, long long put) {     if (!put) return 1;     if (put == 1) return n;     if (put & 1) return (fortza((n * n) % 998244353, put / 2) * n) % 998244353;     return fortza((n * n) % 998244353, put / 2) % 998244353;   }   int main() {     long long n, k, i, j, x;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> k;       for (j = 1; j <= k; ++j) {         cin >> x;         b[x] = (b[x] + fortza((k * n) % 998244353, 998244353 - 2)) % 998244353;         ++a[x];       }     }     n = fortza(n, 998244353 - 2);     for (i = 1, x = 0; i <= 1000006 - 6; ++i)       x = (x + (a[i] * ((n * b[i]) % 998244353)) % 998244353) % 998244353;     cout << x;     return 0;   }   