#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
static const long long N = 1e6 + 9, MOD = 998244353;
long long n, x, y;
long long cnt[N];
vector<long long> a[N];
long long POW(long long x, long long n) {
  if (n == 0) return 1;
  long long tmp = POW(x, n / 2);
  if (n % 2 == 1)
    return (((tmp * tmp) % MOD) * x) % MOD;
  else
    return (tmp * tmp) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (decltype(n) i = 1; i <= n; ++i) {
    cin >> x;
    for (decltype(x) j = 1; j <= x; ++j) {
      cin >> y;
      ++cnt[y];
      a[i].emplace_back(y);
    }
  }
  long long ans = 0;
  for (decltype(n) i = 1; i <= n; ++i) {
    long long res = 0;
    for (auto ele : a[i])
      res = (res + (((cnt[ele]) * POW(n, MOD - 2) % MOD) *
                    POW(a[i].size(), MOD - 2)) %
                       MOD) %
            MOD;
    res = (res * POW(n, MOD - 2)) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
}
