#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
inline long long fastPow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
inline long long fastMul(const long long& a, const long long& b) {
  return (a * b) % MOD;
}
int main() {
  long long N, oneByN;
  cin >> N;
  oneByN = fastPow(N, MOD - 2);
  vector<vector<long long> > input;
  unordered_map<long long, long long> ump;
  for (long long i = 0; i < N; ++i) {
    long long K;
    cin >> K;
    input.push_back(vector<long long>(0, 0));
    for (long long j = 0; j < K; ++j) {
      long long g;
      cin >> g;
      input[i].push_back(g);
      ump[g] += 1;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    long long sz = input[i].size();
    long long oneBySize = fastPow(sz, MOD - 2);
    for (auto g : input[i]) {
      ans =
          (ans + fastMul(oneByN, fastMul(oneBySize, fastMul(ump[g], oneByN)))) %
          MOD;
    }
  }
  cout << ans << '\n';
  return 0;
}
