#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using si = short int;
using uint = unsigned int;
using ull = unsigned long long;
using ld = long double;
void setIO(string name = "") {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  if (name.size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  } else {
  }
  return;
}
const string yes = "YES", no = "NO";
const ll MOD = 998244353;
const ll maxn = 1e6 + 10;
const ll INF = 1e18;
int t = 1;
ll n, k, cnt[maxn];
vector<vector<ll>> a;
ll ans, inv[maxn];
ll fastpow(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % MOD;
    y >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}
void solve() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> k;
    a[i].resize(k);
    for (ll &j : a[i]) {
      cin >> j;
      ++cnt[j];
    }
  }
  for (ll i = 0; i < maxn; ++i) inv[i] = fastpow(i, MOD - 2);
  for (ll i = 0; i < n; ++i) {
    for (const ll &j : a[i]) {
      ans = (ans + ((inv[n] * inv[(ll)a[i].size()]) % MOD) *
                       (inv[n] * cnt[j] % MOD)) %
            MOD;
    }
  }
  cout << ans % MOD << "\n";
  return;
}
int main() {
  setIO("");
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
       << "\n";
  return 0;
}
