#include <bits/stdc++.h>
using namespace std;
long long n, sol = 0, modul = 1000000007;
vector<long long> parent, depth;
long long where(long long pos) {
  if (parent[pos] == -1) return pos;
  long long a = depth[pos];
  long long b = parent[pos];
  long long c = where(parent[pos]);
  parent[pos] = c;
  depth[pos] = (a + depth[b]) % modul;
  return c;
}
void uniona(long long a, long long x, long long b) {
  long long wa = where(a);
  if (wa == b) return;
  sol = (sol + x + depth[a]) % modul;
  depth[wa] = (x + depth[a]) % modul;
  parent[wa] = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  parent.assign(n, -1);
  depth.assign(n, 0);
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    for (long long j = 0; j < k; j++) {
      long long a, b;
      cin >> a >> b;
      a--;
      uniona(a, b, i);
    }
  }
  cout << (sol + modul) % modul << endl;
  return 0;
}
