#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e6 + 5;
const int MOD = 998244353;
long long lgput(long long b, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1) {
      r = 1LL * r * b % MOD;
    }
    p >>= 1;
    b = b * b % MOD;
  }
  return r;
}
long long N;
vector<long long> lista[NMAX + 5];
long long good_kids[NMAX + 5];
long long cati[NMAX + 5];
long long total = 0, special = 0;
long long answer = 0;
void solve() {
  cin >> N;
  for (long long i = 1; i <= N; ++i) {
    cin >> cati[i];
    for (long long j = 1; j <= cati[i]; ++j) {
      long long x;
      cin >> x;
      good_kids[x]++;
      lista[i].push_back(x);
    }
    total = (total + 1LL * N * cati[i] % MOD) % MOD;
  }
  for (long long i = 1; i <= N; ++i) {
    for (auto gift : lista[i]) {
      long long expected =
          1LL * lgput(N, MOD - 2) * lgput(cati[i], MOD - 2) % MOD;
      expected =
          1LL * expected * lgput(N, MOD - 2) % MOD * good_kids[gift] % MOD;
      answer = (answer + expected) % MOD;
    }
  }
  cout << answer << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
