#include <bits/stdc++.h>
using namespace std;
bool isv(char x) {
  if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') {
    return true;
  }
  return false;
}
bool isp(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
string tobin(long long n) {
  string res = "";
  long long i = 0;
  while (n > 0) {
    if (n % 2 == 1) {
      res = res + '1';
    } else {
      res = res + '0';
    }
    n /= 2;
    i++;
  }
  reverse(res.begin(), res.end());
  return res;
}
long long todec(string s) {
  long long n = s.size(), ans = 0, temp = 1;
  for (long long i = n - 1; i >= 0; i--) {
    long long x = s[i] - '0';
    ans += x * temp;
    temp *= 2;
  }
  return ans;
}
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modi(long long a, long long m = 1000000007) {
  return powm(a, m - 2, m);
}
int main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  {
    long long n;
    cin >> n;
    vector<long long> kids[n + 1];
    map<long long, vector<long long> > gifts;
    for (long long i = 1; i <= n; i++) {
      long long sz;
      cin >> sz;
      for (long long j = 1; j <= sz; j++) {
        long long x;
        cin >> x;
        kids[i].push_back(x);
        gifts[x].push_back(i);
      }
    }
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      long long k = kids[i].size();
      for (long long j = 0; j < k; j++) {
        long long cnt = gifts[kids[i][j]].size();
        ans += (((modi(k, 998244353) * cnt) % 998244353) *
                (modi(n, 998244353) % 998244353)) %
               998244353;
      }
    }
    ans = (ans % 998244353 * modi(n, 998244353) % 998244353) % 998244353;
    cout << ans << endl;
  }
  return 0;
}
