#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 1e6 + 7;
int n;
vector<int> a[N];
int cnt[N];
int inv[N];
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int mul(int a, int b) { return a * 1ll * b % MOD; }
int binpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < int(n); ++i) {
    int k;
    scanf("%d", &k);
    a[i].resize(k);
    for (int j = 0; j < int(k); ++j) scanf("%d", &a[i][j]);
    for (int j = 0; j < int(k); ++j) cnt[a[i][j]]++;
  }
  for (int i = 0; i < int(N); ++i) inv[i] = binpow(i, MOD - 2);
  int ans = 0;
  for (int i = 0; i < int(n); ++i)
    for (auto first : a[i])
      ans = add(ans, mul(mul(inv[n], inv[int((a[i]).size())]),
                         mul(cnt[first], inv[n])));
  printf("%d\n", ans);
}
