#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long m) {
  if (b == 0) {
    return 1;
  }
  if (b == 1) {
    return a % m;
  }
  if (b % 2 == 0) {
    long long temp = powmod(a, b / 2, m);
    return temp * temp % m;
  }
  if (b % 2 == 1) {
    long long temp = powmod(a, b / 2, m);
    return a * temp % m * temp % m;
  }
}
long long invmod(long long a, long long m) { return powmod(a, m - 2, m); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long mod = 998244353;
  int count[1000001];
  for (int i = 1; i < 1000001; i++) {
    count[i] = 0;
  }
  int* data = new int[2000001];
  int curr = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    data[curr] = k;
    curr++;
    for (int j = 0; j < k; j++) {
      int pres;
      cin >> pres;
      count[pres]++;
      data[curr] = pres;
      curr++;
    }
  }
  long long resX = 0;
  long long resY = 1;
  curr = 0;
  for (int i = 0; i < n; i++) {
    long long k = data[curr];
    for (int j = curr + 1; j <= curr + k; j++) {
      long long adDiv = k;
      long long adMul = count[data[j]];
      resX *= adDiv;
      resX %= mod;
      resX += ((adMul * resY) % mod);
      resX %= mod;
      resY *= adDiv;
      resY %= mod;
    }
    curr = curr + k + 1;
  }
  resY *= n;
  resY %= mod;
  resY *= n;
  resY %= mod;
  long long res = resX * invmod(resY, mod);
  res %= mod;
  cout << res;
}
