#include <bits/stdc++.h>
using namespace std;
long long n, k, inv[1000002 + 1];
vector<int> v[1000002];
map<int, int> cnt;
void solve() {}
long long add(long long a, long long b) {
  return (a % 998244353 + b % 998244353) % 998244353;
}
long long mul(long long a, long long b) { return a * 1ll * b % 998244353; }
long long powm(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y % 2 == 1) res = mul(res, x);
    x = mul(x, x);
    y /= 2;
  }
  return res;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    cin >> n;
    long long z;
    for (long long i = 0; i < (n); ++i) {
      cin >> k;
      for (long long j = 0; j < (k); ++j) {
        cin >> z;
        v[i].push_back(z);
        cnt[z]++;
      }
    }
    for (long long i = 1; i < (1000002 + 1); ++i)
      inv[i] = powm(i, 998244353 - 2);
    long long ans = 0;
    for (long long i = 0; i < (n); ++i) {
      for (auto j : v[i])
        ans = add(ans, mul(mul(inv[n], inv[v[i].size()]), mul(cnt[j], inv[n])));
    }
    cout << ans;
  }
}
