#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const long long int MAXN = 2e5 + 5;
const long long int N = 2e5 + 5;
long long int n, m;
long long int binpow(long long int n, long long int p) {
  long long int res = 1;
  while (p > 0) {
    if (p & 1) res = res * n;
    n = n * n;
    p >>= 1;
  }
  return res;
}
long long int power(long long int n, long long int p) {
  long long int res = 1;
  n %= 998244353;
  while (p > 0) {
    if (p & 1) res = (res * n) % 998244353;
    n = (n * n) % 998244353;
    p >>= 1;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2);
}
long long int fact[MAXN], inv[MAXN], invfact[MAXN];
void initFactorials() {
  fact[0] = 1;
  for (long long int i = 1; i < MAXN; i++) {
    fact[i] = (fact[i - 1] * i * 1LL) % 998244353;
  }
  inv[1] = 1;
  for (long long int i = 2; i < MAXN; i++)
    inv[i] = inv[998244353 % i] * (998244353 - 998244353 / i) % 998244353;
  invfact[0] = 1;
  for (long long int i = 1; i < MAXN; i++)
    invfact[i] = (invfact[i - 1] * inv[i]) % 998244353;
}
long long int nCrMod(long long int n, long long int r) {
  if (n < r) return 0;
  if (r == 0) return 1;
  long long int num = fact[n],
                invden = (invfact[r] * invfact[n - r]) % 998244353;
  return (num * invden) % 998244353;
}
const long long int MXN = 1e6 + 7;
vector<long long int> a[MXN];
long long int cnt[MXN];
long long int inverse[MXN];
long long int mul(long long int a, long long int b) {
  return a * b % 998244353;
}
void solve() {
  long long int x, y, z, k;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> k;
    a[i].resize(k);
    for (long long int j = 0; j < k; j++) cin >> a[i][j];
    for (long long int j = 0; j < k; j++) cnt[a[i][j]]++;
  }
  for (long long int i = 0; i < MXN; i++) inverse[i] = modInverse(i, 998244353);
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int x : a[i]) {
      y = mul(mul(inverse[n], inverse[a[i].size()]), mul(cnt[x], inverse[n]));
      ans = (ans + y) % 998244353;
      ans = (ans + 998244353) % 998244353;
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  clock_t begin = clock();
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  cerr << "Time elapsed: " << (clock() - begin) * 1000.0 / CLOCKS_PER_SEC
       << "ms" << '\n';
}
