#include <bits/stdc++.h>
using namespace std;
vector<int> requests[1000000];
long long occurrences[1000001];
long long numerator[1000000];
long long denominator[1000000];
long long MOD = 998244353;
long long inverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  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() {
  for (int i = 1; i <= 1000000; i++) {
    occurrences[i] = 0;
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      requests[i].push_back(a);
      occurrences[a]++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < requests[i].size(); j++) {
      numerator[i] += occurrences[requests[i][j]];
    }
    denominator[i] = requests[i].size();
  }
  long long res1 = 0;
  long long res2 = 1;
  for (int i = 0; i < n; i++) {
    long long r1 = res1 * denominator[i] + res2 * numerator[i];
    long long r2 = res2 * denominator[i];
    res1 = r1 % MOD;
    res2 = r2 % MOD;
  }
  res2 *= n;
  res2 %= MOD;
  res2 *= n;
  res2 %= MOD;
  long long result = inverse(res2, MOD) * res1 % MOD;
  cout << result << "\n";
}
