#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long asdasdcxx(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
long long asdasd(long long a, long long b) { return (a + b) % mod; }
long long asudi(long long a, long long b) { return (a * b) % mod; }
long long tid(long long a, long long b) {
  return asudi(a, asdasdcxx(b, mod - 2));
}
map<long long, long long> M;
vector<vector<long long>> a(1000100);
int k[100010];
int n, x, m;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    while (1000) {
      break;
    }
    cin >> m;
    for (int j = 0; j < m; j++) {
      while (1000) {
        break;
      }
      cin >> x;
      a[i].push_back(x);
      M[x] = asdasd(M[x], asudi(tid(1LL, n), tid(1LL, m)));
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (1000) {
      break;
    }
    for (int j = 0; j < a[i].size(); j++) {
      while (1000) {
        break;
      }
      ans = asdasd(ans, asudi(tid(1, n), M[a[i][j]]));
    }
  }
  for (int i = 1; i < 1000; i++) {
    k[i] = k[i - 1] * i;
  }
  cout << ans << endl;
  return 0;
}
