#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
using namespace std;
const long long M = 998244353;
long long mul(long long a, long long b) { return (a * (long long)b) % M; }
long long pw(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2 == 0) {
      a = mul(a, a);
      n /= 2;
    } else {
      res = mul(res, a);
      n--;
    }
  }
  return res;
}
long long inv(long long first) { return pw(first, M - 2); }
long long modInverse(long long a, long long m) {
  a = a % m;
  for (long long first = 1; first < m; first++)
    if ((a * first) % m == 1) return first;
  return 1;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void lowest(long long &den3, long long &num3) {
  long long common_factor = gcd(num3, den3);
  den3 = den3 / common_factor;
  num3 = num3 / common_factor;
}
void addFraction(long long num1, long long den1, long long num2, long long den2,
                 long long &num3, long long &den3) {
  den3 = gcd(den1, den2);
  den3 = (den1 * den2) / den3;
  num3 = (num1) * (den3 / den1) + (num2) * (den3 / den2);
  lowest(den3, num3);
}
long long go(long long a, long long b) {
  long long c = gcd(a, b);
  a = a / c;
  b = b / c;
  long long d = pw(b, 998244353 - 2);
  long long ans = ((a % 998244353) * (d % 998244353)) % 998244353;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> m;
  vector<long long> a[n];
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    for (long long j = 0; j < k; j++) {
      long long first;
      cin >> first;
      a[i].push_back(first);
      m[first]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long p = 0;
    for (long long j = 0; j < a[i].size(); ++j) {
      p += (m[a[i][j]]);
      p %= 998244353;
    }
    long long d = 1;
    d = (n * n * a[i].size()) % 998244353;
    d = go(go(go(p, n) % 998244353, n) % 998244353, a[i].size()) % 998244353;
    ans += d;
    ans %= 998244353;
  }
  cout << ans;
  return 0;
}
