#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const long long int ths = 1LL << 40;
const int NN = 5e5 + 6;
long long int pw(long long int a, long long int n) {
  long long int r = 1;
  while (n) {
    if (n & 1) r = (r * a) % cmod;
    a = (a * a) % cmod;
    n >>= 1;
  }
  return r;
}
long long int modInv(long long int a) { return pw(a, cmod - 2); }
long long int cnt[M], prob[M];
void solve() {
  long long int n;
  cin >> n;
  long long int invn = modInv(n);
  for (int i = 0; i < n; i++) {
    long long int k;
    cin >> k;
    long long int invk = modInv(k);
    for (int j = 0; j < k; j++) {
      long long int x;
      cin >> x;
      x--;
      cnt[x]++;
      prob[x] += (invn % cmod * invk % cmod) % cmod;
      prob[x] %= cmod;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < M; i++) {
    ans += (prob[i] % cmod * cnt[i] % cmod * invn % cmod) % cmod;
    ans %= cmod;
  }
  cout << ans;
  cout << '\n';
  return;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
