#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int mod = 998244353;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long pwr(long long a, long long pw) {
  long long ret = 1;
  while (pw > 0) {
    if (pw & 1) ret = ret * a % mod;
    a = a * a % mod;
    pw >>= 1;
  }
  return ret;
}
long long modinv(long long a) { return pwr(a, mod - 2); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> k(n + 1);
  vector<int> arr[n + 1];
  vector<int> cnt(1000005, 0);
  for (int i = 1; i <= n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int a;
      cin >> a;
      arr[i].push_back(a);
      cnt[a]++;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long prob = modinv(n) * modinv(k[i]) % mod;
    for (int a : arr[i]) {
      ans = (ans + prob * (cnt[a] * modinv(n) % mod)) % mod;
    }
  }
  cout << ans << "\n";
  return 0;
}
