#include <bits/stdc++.h>
using namespace std;
const long long p = 998244353;
long long n, ans, a[1000010], c[1000010], cnt[1000010];
long long ksm(long long x, long long y) {
  long long xlh = 1;
  while (y) {
    if (y & 1) xlh = xlh * x % p;
    x = x * x % p;
    y /= 2;
  }
  return xlh;
}
int main() {
  long long i, j, x;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (j = 1; j <= a[i]; j++) {
      scanf("%lld", &x);
      cnt[x]++;
      c[x] = (c[x] + ksm(a[i], p - 2) * ksm(n, p - 2) % p) % p;
    }
  }
  for (i = 1; i <= 1000000; i++)
    if (cnt[i]) {
      ans = (ans + c[i] * cnt[i] % p * ksm(n, p - 2) % p) % p;
    }
  printf("%lld", ans);
}
