#include <bits/stdc++.h>
using namespace std;
long long int add_w(long long int a, long long int b) {
  return (a + b) % 998244353;
}
long long int mul(long long int a, long long int b) {
  return ((a % 998244353) * (b % 998244353)) % 998244353;
}
int gcdExtended(long long int a, long long int b, long long int *x,
                long long int *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long int modo_inverse(long long int a) {
  long long int x, y;
  long long int g = gcdExtended(a, 998244353, &x, &y);
  if (g != 1) cout << "hello" << endl;
  return (x % 998244353 + 998244353) % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[1000005] = {0};
    vector<vector<long long int>> v;
    for (long long int i = 0; i < n; i++) {
      long long int k;
      cin >> k;
      vector<long long int> v1;
      for (long long int j = 0; j < k; j++) {
        long long int x;
        cin >> x;
        arr[x]++;
        v1.push_back(x);
      }
      v.push_back(v1);
    }
    long long int ans = 0;
    long long int deno = mul(n, n);
    for (long long int i = 0; i < v.size(); i++) {
      long long int x = mul(deno, v[i].size());
      long long int y = modo_inverse(x);
      for (long long int j = 0; j < v[i].size(); j++) {
        ans = add_w(ans, mul(y, arr[v[i][j]]));
      }
    }
    cout << ans;
  }
  return 0;
}
