#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
long long quick(long long a, long long b) {
  long long ans = 1 % mod;
  while (b) {
    if (b & 1) ans = (ans % mod * a % mod) % mod;
    a = (a % mod * a % mod) % mod;
    b >>= 1;
  }
  return ans % mod;
}
int yy[1005000], m1[1005000];
vector<int> vv[1005000];
int main() {
  int n;
  read(n);
  map<int, int> mm;
  int cutt = 0;
  for (int i = 1; i <= n; i++) {
    int m;
    read(m);
    for (int j = 1; j <= m; j++) {
      int x;
      read(x);
      if (mm[x] == 0) yy[cutt++] = x;
      mm[x]++;
      vv[i].push_back(x);
    }
  }
  for (int i = 0; i < cutt; ++i) {
    m1[i] = quick(mm[yy[i]], mod - 2);
  }
  long long ans = 0;
  long long sss = quick(cutt, mod - 2);
  long long s1 = quick(n, mod - 2);
  for (int i = 1; i <= n; i++) {
    int y = vv[i].size();
    long long s2 = quick(y, mod - 2);
    for (int j = 0; j < vv[i].size(); j++) {
      int x = vv[i][j];
      int a = mm[x];
      ans = ((ans % mod) % mod +
             ((s1 * s2 % mod) % mod * (a * s1 % mod) % mod) % mod) %
            mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
