#include <bits/stdc++.h>
using namespace std;
long long binpow(long long x, long long y) {
  long long res = 1;
  x %= 998244353;
  while (y != 0) {
    if (y & 1) res = (res * x) % 998244353;
    x = (x * x) % 998244353;
    y >>= 1;
  }
  return res;
}
long long inv(long long a) { return binpow(a, 998244353 - 2); }
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long get(long long a, long long b) {
  long long c = gcd(a, b);
  a = a / c;
  b = b / c;
  return (a * inv(b)) % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<vector<int> > vect(n + 1);
  vector<int> cnt(1000005, 0);
  for (int i = (0); i < (n); i += 1) {
    int k;
    cin >> k;
    for (int j = (0); j < (k); j += 1) {
      int item;
      cin >> item;
      cnt[item]++;
      vect[i].push_back(item);
    }
  }
  long long ans = 0;
  for (int i = (0); i < (n); i += 1) {
    for (int j = (0); j < (vect[i].size()); j += 1) {
      long long hore = cnt[vect[i][j]];
      long long dole = n * (long long)vect[i].size() * n;
      ans += get(hore, dole);
      ans %= 998244353;
    }
  }
  cout << ans << endl;
  return 0;
}
