#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
                          long long int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long int modInverse(long long int a, long long int m) {
  long long int x, y;
  long long int g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    return 0;
  else {
    long long int res = (x % m + m) % m;
    return res;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int mod = 998244353;
  long long int n;
  cin >> n;
  vector<long long int> a(n + 1);
  map<long long int, long long int> freq;
  vector<long long int> store[n + 1];
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    for (long long int j = 1; j <= a[i]; j++) {
      long long int in;
      cin >> in;
      store[i].push_back(in);
      freq[in]++;
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int x = i;
    for (long long int j = 0; j < a[i]; j++) {
      long long int denom = n * n * a[i];
      long long int y = store[i][j];
      long long int nom = freq[y];
      long long int cc = gcd(nom, denom);
      nom /= cc;
      denom /= cc;
      ans = (ans % mod + (nom * modInverse(denom, mod)) % mod) % mod;
    }
    ans %= mod;
  }
  cout << ans % mod << endl;
}
