#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5, MXX = 23;
const long long mod = 998244353, inf = 1e18 + 6;
int cnk[MX], n;
vector<int> kad[MX];
pair<long long, long long> ans;
long long multi(long long x, long long y) { return (x * y) % mod; }
long long pw(long long x, long long y) {
  if (!y) return 1;
  long long ans = pw(x, y / 2);
  ans = multi(ans, ans);
  return y & 1 ? multi(ans, x) : ans;
}
long long dv(long long x, long long y) { return multi(x, pw(y, mod - 2)); }
pair<long long, long long> sum(pair<long long, long long> x,
                               pair<long long, long long> y) {
  return make_pair((multi(x.first, y.second) + multi(y.first, x.second)) % mod,
                   multi(y.second, x.second));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
  cin >> n;
  ans = make_pair(0, 1);
  for (int i = 0; i < n; ++i) {
    long long k;
    cin >> k;
    for (int t = 0; t < k; ++t) {
      int a;
      cin >> a;
      kad[i].push_back(a);
      cnk[a]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    long long val = (long long)n * (kad[i].size());
    val %= mod;
    for (auto v : kad[i]) {
      ans = sum(ans, make_pair(cnk[v], multi(val, n)));
    }
  }
  cout << dv(ans.first, ans.second) << "\n";
  return 0;
}
