#include <bits/stdc++.h>
template <class T>
inline void read(T &k) {
  k = 0;
  long long flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    k = k * 10 + c - '0';
    c = getchar();
  }
  k *= flag;
}
using namespace std;
const int N = 1000005;
int n, m, k, s, t;
long long a[N], b[N], o, u, ans;
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return;
  }
  exgcd(b % a, a, y, x);
  x -= b / a * y;
}
long long inv(long long a) {
  long long x, y;
  exgcd(a, 998244353, x, y);
  return x;
}
int main() {
  read(n);
  u = inv(n);
  for (int i = 1; i <= n; ++i) {
    read(k);
    o = inv(k) % 998244353;
    for (int j = 1; j <= k; ++j) {
      read(s);
      a[s] = (a[s] + u * o) % 998244353;
      b[s] += 1;
    }
  }
  for (int j = 1; j <= 1000000; ++j) {
    ans = (ans + a[j] * b[j] % 998244353 * u) % 998244353;
  }
  ans = (ans + 998244353) % 998244353;
  cout << ans << endl;
}
