#include <bits/stdc++.h>
using namespace std;
int main() {
  const int N = 1e6 + 5, mod = 998244353;
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> ks(n);
  vector<int> gs(N);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int p;
      cin >> p;
      --p;
      ks[i].push_back(p);
      gs[p]++;
    }
  }
  int inv[N];
  inv[1] = 1;
  for (int i = 2; i < N; i++)
    inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int k = ks[i].size();
    auto y = 1LL * inv[k] * inv[n] % mod * inv[n] % mod;
    for (int j = 0; j < k; j++) {
      auto x = y * gs[ks[i][j]] % mod;
      ans = (ans + x) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}
