#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  int s = 0, c = getchar();
  x = 0;
  while (isspace(c)) c = getchar();
  if (c == 45) s = 1, c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (s) x = -x;
}
template <typename T>
void write(T x, char c = ' ') {
  int b[40], l = 0;
  if (x < 0) putchar(45), x = -x;
  while (x > 0) b[l++] = x % 10, x /= 10;
  if (!l) putchar(48);
  while (l) putchar(b[--l] | 48);
  putchar(c);
}
const int N = 1e6 + 8;
const long long mo = 998244353;
long long sum[N];
int cnt[N];
int n, ma;
long long invn, invk, ans;
long long kuai(int a, long long b) {
  long long qwq = 1;
  long long aa = a;
  while (b) {
    if (b & 1) qwq = qwq * aa % mo;
    aa = aa * aa % mo;
    b >>= 1;
  }
  return qwq;
}
int main(void) {
  read(n);
  invn = kuai(n, mo - 2);
  ma = 0;
  for (int k, i = 1; i <= n; ++i) {
    read(k);
    invk = kuai(k, mo - 2);
    for (int u, j = 1; j <= k; ++j) {
      read(u);
      ma = ((((ma) > (u) ? (ma) : (u))));
      sum[u] = (sum[u] + invk) % mo;
      ++cnt[u];
    }
  }
  ans = 0;
  for (int i = 1; i <= ma; ++i) {
    if (cnt[i] == 0) continue;
    ans = (ans + sum[i] * cnt[i] % mo * invn % mo) % mo;
  }
  ans = (ans * invn) % mo;
  printf("%lld\n", ans);
  return 0;
}
