#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long po(long long x, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) ans = (ans * x) % mod;
    x = (x * x) % mod;
    n /= 2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<vector<long long> > v;
    v.assign(n, vector<long long>());
    map<long long, long long> m;
    long long k, x;
    for (int i = 0; i < n; i++) {
      cin >> k;
      for (int j = 0; j < k; j++) {
        cin >> x;
        v[i].push_back(x);
        if (m.find(x) == m.end())
          m.insert(make_pair(x, 1));
        else
          m[x]++;
      }
    }
    long long s = 0, s1 = 0;
    for (int i = 0; i < n; i++) {
      s1 = 0;
      long long m1 = po(v[i].size(), mod - 2);
      for (auto h = v[i].begin(); h != v[i].end(); h++)
        s1 += (m[*h]), s1 %= mod;
      s += ((m1 * s1) % mod);
      s %= mod;
    }
    long long z = po(n, mod - 2);
    z *= z;
    z %= mod;
    s *= z;
    s %= mod;
    cout << s << endl;
  }
  return 0;
}
