#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return ((binpow(a, n - 1) % 998244353) * (a % 998244353)) % 998244353;
  else {
    long long b = binpow(a, n / 2) % 998244353;
    return (b * b) % 998244353;
  }
}
long long bindiv(long long a, long long b) {
  long long inv = binpow(b, 998244353 - 2);
  return (a * inv) % 998244353;
}
signed main() {
  long long n;
  cin >> n;
  vector<vector<long long> > k;
  vector<long long> present;
  present.assign(1000001, 0);
  k.assign(n, vector<long long>());
  long long len, temp;
  for (long long i = 0; i < n; i++) {
    cin >> len;
    for (long long j = 0; j < len; j++) {
      cin >> temp;
      k[i].push_back(temp);
      present[temp]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long si = k[i].size();
    for (long long j = 0; j < si; j++) {
      long long y = n * si * n;
      long long x = present[k[i][j]];
      ans = (ans % 998244353 + bindiv(x, y)) % 998244353;
    }
  }
  cout << ans;
}
