#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> extnuc(long long a, long long b) {
  if (b == 0) return pair<long long, long long>(1, 0);
  pair<long long, long long> d = extnuc(b, a % b);
  return pair<long long, long long>(d.second, d.first - d.second * (a / b));
}
long long modi(long long n) {
  pair<long long, long long> d = extnuc(n, 998244353);
  return ((d.first % 998244353) + 998244353) % 998244353;
}
long long m, n;
int ocr[2000005];
vector<int> ed[2000005];
int main() {
  long long i, j, test, cas = 0;
  long long a, b, u, d, cu, cd, g, re, oc, x;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &oc);
    while (oc--) {
      scanf("%lld", &x);
      ed[i].push_back(x);
      ocr[x]++;
    }
  }
  u = 0;
  d = 1;
  for (i = 1; i <= n; i++) {
    cu = 0;
    cd = ed[i].size();
    for (j = 0; j < ed[i].size(); j++) {
      cu += ocr[ed[i][j]];
      cu %= 998244353;
    }
    u = u * cd + cu * d;
    d = d * cd;
    u %= 998244353;
    d %= 998244353;
  }
  d *= n;
  d %= 998244353;
  d *= n;
  d %= 998244353;
  re = u * modi(d);
  re %= 998244353;
  printf("%lld\n", re);
  return 0;
}
