#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long modpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % mod;
    }
    b /= 2;
    a = (a * a) % mod;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<vector<long long>> a(n);
  vector<long long> freq(1e6 + 1);
  for (long long i = 0; i < n; i++) {
    long long m;
    cin >> m;
    a[i] = vector<long long>(m);
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
      freq[a[i][j]]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long k = a[i].size();
    long long temp = 0;
    for (long long j = 0; j < k; j++) {
      temp = (temp + freq[a[i][j]]) % mod;
    }
    temp = (temp * modpow(k, mod - 2)) % mod;
    ans = (ans + temp) % mod;
  }
  ans = (ans * modpow(n, mod - 2)) % mod;
  ans = (ans * modpow(n, mod - 2)) % mod;
  cout << ans << "\n";
  return 0;
}
