#include <bits/stdc++.h>
using namespace std;
long long modInverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<vector<long long>> v;
  v.assign(n, vector<long long>());
  vector<long long> v1;
  v1.assign(1000008, 0);
  long long k;
  long long a;
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    for (long long j = 0; j < k; j++) {
      cin >> a;
      v[i].push_back(a);
      v1[a] += 1;
    }
  }
  long long ans = 0;
  long long mo = 998244353;
  for (auto x : v) {
    for (auto y : x) {
      ans += modInverse(x.size(), mo) * v1[y];
      ans %= mo;
    }
  }
  ans *= modInverse((n * n) % mo, mo);
  ans %= mo;
  cout << ans << endl;
  return 0;
}
