#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10;
const long long mod = 998244353;
vector<long long> a[maxn], b[maxn];
long long num[maxn];
long long qpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  long long n, Max = 0;
  cin >> n;
  for (long long i = 1, k, x; i <= n; i++) {
    cin >> k;
    while (k--) {
      cin >> x;
      Max = max(x, Max);
      a[i].push_back(x);
      b[x].push_back(i);
    }
  }
  for (long long i = 1; i <= Max; i++) {
    if (b[i].size()) num[i] = b[i].size() * qpow(n, mod - 2) % mod;
  }
  long long ans = 0;
  long long pp = qpow(n, mod - 2) % mod;
  for (int i = 1; i <= n; i++) {
    long long p = qpow(a[i].size(), mod - 2) % mod;
    long long w = 0;
    for (int j = 0; j < a[i].size(); j++)
      w = (w + p * num[a[i][j]] % mod) % mod;
    ans = (ans + pp * w % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
