#include <bits/stdc++.h>
using namespace std;
namespace Fread {
const int MAXN = 1 << 20;
char buffer[MAXN], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buffer) + fread(buffer, 1, MAXN, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
inline int read() {
  int f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
inline long long readll() {
  long long f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
const int MAXN = 1e6 + 5, MOD = 998244353;
inline int pow_mod(int x, int i) {
  int y = 1;
  while (i) {
    if (i & 1) y = (long long)y * x % MOD;
    x = (long long)x * x % MOD;
    i >>= 1;
  }
  return y;
}
int n, cnt[MAXN], sz[MAXN];
vector<int> a[MAXN];
int main() {
  n = read();
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    sz[i] = read();
    for (int j = 0; j < sz[i]; ++j) a[i].push_back(read()), cnt[a[i][j]]++;
    sum = (sum + sz[i]) % MOD;
  }
  int in = pow_mod(n, MOD - 2), ans = 0;
  for (int i = 1; i <= n; ++i) {
    int ik = pow_mod(sz[i], MOD - 2);
    for (int j = 0; j < sz[i]; ++j) {
      ans = (ans + (long long)in * ik % MOD * cnt[a[i][j]] % MOD) % MOD;
    }
  }
  ans = (long long)ans * in % MOD;
  cout << ans << endl;
  return 0;
}
