#include <bits/stdc++.h>
using namespace std;
int MAX_INT = numeric_limits<int>::max();
int MIN_INT = numeric_limits<int>::min();
unsigned long long MAX_LL = numeric_limits<long long>::max();
unsigned long long MIN_LL = numeric_limits<long long>::min();
unsigned long long mod = 998244353;
unsigned long long pow_mod(unsigned long long a, unsigned long long p,
                           unsigned long long m) {
  unsigned long long res = 1;
  while (p > 0) {
    if (p % 2) res *= a;
    res %= m;
    a = a * a;
    a %= m;
    p = p / 2;
  }
  return res;
}
unsigned long long modInverse(unsigned long long a, unsigned long long m) {
  return pow_mod(a % m, m - 2, m);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unsigned long long n;
  cin >> n;
  vector<vector<unsigned long long>> arr(n);
  vector<unsigned long long> a(1e6 + 1, 0);
  unsigned long long y = 1;
  unsigned long long k;
  unsigned long long x = 0;
  unsigned long long kmul = 1;
  for (int i = 0; i < n; i++) {
    cin >> k;
    kmul *= k;
    kmul = kmul % mod;
    arr[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> arr[i][j];
      a[arr[i][j]]++;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < arr[i].size(); j++)
      x += (((a[arr[i][j]] * kmul) % mod) *
            modInverse((unsigned long long)arr[i].size(), mod)) %
           mod;
  x = x % mod;
  y = (y * (((n * n) % mod) * kmul) % mod) % mod;
  cout << (x * modInverse(y, mod)) % mod << '\n';
}
