#include <bits/stdc++.h>
using namespace std;
struct frac {
  long long num, den;
  frac() {
    num = 0ll;
    den = 1ll;
  }
  frac(long long a, long long b) { num = a, den = b; }
  frac operator+(const frac& b) {
    num = (num * b.den) % 998244353ll;
    num += (b.num * den) % 998244353ll;
    den = (den * b.den) % 998244353ll;
    num %= 998244353ll;
    return *this;
  }
};
long long fast_pow(long long n, long long e) {
  if (e == 0ll) return 1ll;
  if (e == 1ll) return n;
  long long tmp = fast_pow(n, e / 2ll);
  tmp = (tmp * tmp) % 998244353ll;
  if (e & 1ll) return (tmp * n) % 998244353ll;
  return tmp;
}
long long fermat_mmi(long long x) { return fast_pow(x, 998244353ll - 2ll); }
int acnt[1000006];
int k[1000006];
frac pdraw[1000006];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k[i];
    for (int j = 1; j <= k[i]; j++) {
      int aij;
      cin >> aij;
      acnt[aij]++;
      frac adder(1ll, k[i]);
      pdraw[aij] = (pdraw[aij] + adder);
    }
  }
  frac ans(0ll, 1ll);
  for (int i = 1; i <= 1000000; i++) {
    pdraw[i].den = (pdraw[i].den * n) % 998244353ll;
    pdraw[i].den = (pdraw[i].den * n) % 998244353ll;
    pdraw[i].num = (pdraw[i].num * acnt[i]) % 998244353ll;
    ans = (ans + pdraw[i]);
  }
  long long ansnum = (ans.num * fermat_mmi(ans.den)) % 998244353ll;
  cout << ansnum << '\n';
  return 0;
}
