#include <bits/stdc++.h>
using namespace std;
inline long long bip(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int maxn = 1e9;
const long long inf = 1e18;
const int mod = 998244353;
const int N = 1e6 + 10;
vector<long long> a[N];
void solve() {
  long long n;
  cin >> n;
  vector<long long> cnt(N, 0);
  vector<long long> k(n + 10);
  for (int i = 1; i <= n; i++) {
    cin >> k[i];
    for (int j = 1; j <= k[i]; j++) {
      long long x;
      cin >> x;
      cnt[x]++;
      a[i].push_back(x);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (auto v : a[i])
      ans = (ans + (bip((n * n * k[i]) % mod, mod - 2, mod) * cnt[v]) % mod) %
            mod;
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
    cout << '\n';
  }
}
