#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> v) {     os <<  (   << v.first <<  ,   << v.second <<  ) ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os <<    ;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<vector<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<set<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     int i = 0;     for (auto it : v) {       if (i > 0) {         os <<    ;       }       os << it;       i++;     }     return os;   }   using Graph = vector<vector<int>>;   const ll MAX_S = 2e5;   vector<ll> check(vector<ll> &x) {     vector<ll> anss(x.size());     for (int i = 0; i < int(x.size()) - 1; ++i) {       anss[i + 1] = x[i + 1] - x[i];     }     anss[0] = x[0];     return anss;   }   using Value = ll;   const Value ini = ll(1e18);   Value connect(Value al, const Value ar) { return min(al, ar); }   Value dat[1100001];   struct segtree {     int N;     segtree() {}     segtree(int n) {       N = 1;       while (N < n) N *= 2;       for (int x = 0; x < N; ++x) {         dat[x + N - 1] = ini;       }       for (int x = N - 2; x >= 0; --x) {         dat[x] = connect(dat[x * 2 + 1], dat[x * 2 + 2]);       }     }     void update(int k, const Value &a) {       k += N - 1;       dat[k] = a;       while (k > 0) {         k = (k - 1) >> 1;         dat[k] = connect(dat[k * 2 + 1], dat[k * 2 + 2]);       }     }     Value query(int a, int b) { return query(a, b, 0, 0, N); }     Value query(int a, int b, int k, int l, int r) {       if (r <= a || b <= l) return ini;       if (a <= l && r <= b) return dat[k];       const int m = (l + r) / 2;       return connect(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));     }   };   vector<int> nums(int(3e5));   ll to_n(string st) {     ll num = 0;     for (auto c : st) {       num *= 2;       num += c -  0 ;     }     return num;   }   string to_s(int sz, ll num) {     string st;     for (int i = 0; i < sz; ++i) {       st.push_back( 0  + (num % 2));       num /= 2;     }     reverse(st.begin(), st.end());     return st;   }   const int mod = 998244353;   struct Mod {    public:     int num;     Mod() : Mod(0) { ; }     Mod(long long int n) : num((n % mod + mod) % mod) {}     Mod(int n) : Mod(static_cast<long long int>(n)) { ; }     operator int() { return num; }   };   Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }   Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }   Mod operator+(const Mod a, const long long int b) { return b + a; }   Mod operator++(Mod &a) { return a + Mod(1); }   Mod operator-(const Mod a, const Mod b) {     return Mod((mod + a.num - b.num) % mod);   }   Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }   Mod operator--(Mod &a) { return a - Mod(1); }   Mod operator*(const Mod a, const Mod b) {     return Mod(((long long)a.num * b.num) % mod);   }   Mod operator*(const long long int a, const Mod b) { return Mod(a) * b; }   Mod operator*(const Mod a, const long long int b) { return Mod(b) * a; }   Mod operator*(const Mod a, const int b) { return Mod(b) * a; }   Mod operator+=(Mod &a, const Mod b) { return a = a + b; }   Mod operator+=(long long int &a, const Mod b) { return a = a + b; }   Mod operator-=(Mod &a, const Mod b) { return a = a - b; }   Mod operator-=(long long int &a, const Mod b) { return a = a - b; }   Mod operator*=(Mod &a, const Mod b) { return a = a * b; }   Mod operator*=(long long int &a, const Mod b) { return a = a * b; }   Mod operator*=(Mod &a, const long long int &b) { return a = a * b; }   Mod operator^(const Mod a, const int n) {     if (n == 0) return Mod(1);     Mod res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   Mod mod_pow(const Mod a, const long long n) {     if (n == 0) return Mod(1);     Mod res = mod_pow((a * a), (n / 2));     if (n % 2) res = res * a;     return res;   }   Mod inv(const Mod a) { return a ^ (mod - 2); }   Mod operator/(const Mod a, const Mod b) {     assert(b.num != 0);     return a * inv(b);   }   Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; }   Mod operator/=(Mod &a, const Mod b) { return a = a / b; }   Mod fact[1024000], factinv[1024000];   void init(const int amax = 1024000) {     fact[0] = Mod(1);     factinv[0] = 1;     for (int i = 0; i < amax - 1; ++i) {       fact[i + 1] = fact[i] * Mod(i + 1);       factinv[i + 1] = factinv[i] / Mod(i + 1);     }   }   Mod comb(const int a, const int b) {     return fact[a] * factinv[b] * factinv[a - b];   }   int main() {     int N;     cin >> N;     vector<Mod> pers(int(1e6));     vector<int> cnts(int(1e6));     for (int i = 0; i < N; ++i) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; ++j) {         int a;         scanf( %d , &a);         a--;         cnts[a]++;         pers[a] += Mod(1) / Mod(N) / Mod(k);       }     }     Mod answer = Mod(0);     for (int i = 0; i < int(1e6); ++i) {       answer += pers[i] * Mod(cnts[i]) / Mod(N);     }     cout << answer.num << endl;     return 0;   }