#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long fpow(long long base, long long exp) {
  long long result = 1;
  while (exp) {
    if (exp & 1) result = (result * base) % MOD;
    exp >>= 1;
    base = (base * base) % MOD;
  }
  return result;
}
const int MAXN = 1e6 + 10;
long long am[MAXN], inv[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0, ThxDem = MAXN; i < ThxDem; ++i) inv[i] = fpow(i, MOD - 2);
  long long ans = 0, n;
  cin >> n;
  vector<vector<int>> a(n);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    int k;
    cin >> k;
    a[i].resize(k);
    for (int j = 0, ThxDem = k; j < ThxDem; ++j) cin >> a[i][j], am[a[i][j]]++;
  }
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    long long k = int(a[i].size());
    for (int j = 0, ThxDem = k; j < ThxDem; ++j) {
      long long p = inv[n] * inv[k] % MOD;
      long long q = am[a[i][j]] * inv[n] % MOD;
      ans = (ans + p * q) % MOD;
    }
  }
  cout << ans << "\n";
}
