#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &a, U b) {
  a = (a > b ? b : a);
}
template <typename T, typename U>
inline void amax(T &a, U b) {
  a = (a > b ? a : b);
}
const int mod = 998244353;
map<int, int> freq;
long long int expo(long long int n, long long int p, long long int M) {
  long long int res = 1;
  while (p) {
    if (p & 1) res = (res * n) % M;
    n = (n * n) % M;
    p >>= 1;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> k(n);
  for (int i = 0; i < n; ++i) {
    int L;
    cin >> L;
    vector<int> p;
    for (int j = 0; j < L; ++j) {
      int x;
      cin >> x;
      ++freq[x];
      p.push_back(x);
    }
    k[i] = p;
  }
  int64_t ans = 0, chooseX = expo(n, mod - 2, mod);
  for (int i = 0; i < n; ++i) {
    int64_t chooseK = expo(((int)k[i].size()), mod - 2, mod);
    for (int j : k[i]) {
      int64_t here = chooseX;
      here *= chooseK;
      here %= mod;
      here *= freq[j];
      here %= mod;
      here *= chooseX;
      here %= mod;
      ans += here;
      ans %= mod;
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tests = 1;
  while (tests--) {
    solve();
  }
}
