#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (int)((y % 2 == 0) ? p : (x * p) % m);
}
int modInverse(int a, int m) { return power(a, m - 2, m); }
int n;
long long kids[1234567], prob[1234567], ans;
int main() {
  scanf("%d", &n);
  set<int> st;
  for (int i = 0, k; i < n; i++) {
    scanf("%d", &k);
    int k_1 = modInverse(k, MOD);
    for (int j = 0, tmp; j < k; j++) {
      scanf("%d", &tmp);
      kids[tmp]++;
      prob[tmp] = (prob[tmp] + k_1) % MOD;
    }
  }
  long long tot_1 = modInverse(n, MOD);
  for (int i = 0; i < 1234567; i++) {
    prob[i] = (prob[i] * tot_1) % MOD;
    ans = (ans + (prob[i] * ((kids[i] * tot_1) % MOD)) % MOD) % MOD;
  }
  cout << ans << endl;
  return 0;
}
