#include <bits/stdc++.h>
using namespace std;
double _eps = 1e-6;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int arr[1000000 + 100];
vector<int> v[1000000 + 10];
long long egcd(long long a, long long b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long miverse(long long a, long long m) {
  long long x, y;
  egcd(a, m, x, y);
  return (x + m) % m;
}
set<int> st;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      v[i].push_back(x);
      arr[x]++;
    }
  }
  long long md = 998244353;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int xs = v[i].size();
    long long sum = 0;
    for (int x : v[i]) {
      sum += arr[x];
    }
    ans = (ans + (sum * miverse(n * n * xs, md)) % md) % md;
  }
  cout << ans;
  puts("");
  return 0;
}
