#include <bits/stdc++.h>
using namespace std;
long long root[500000], dep[500000], ans = 0;
map<pair<long long, long long>, long long> ma;
long long mod = 1000000007;
long long fin(long long r) {
  if (root[r] == r) return r;
  long long op = root[r];
  long long np = fin(root[r]);
  dep[r] += (dep[op]);
  root[r] = np;
  return root[r];
}
void connect(long long child, long long par, long long wei) {
  long long chi = child;
  long long root_child = fin(child);
  root[root_child] = par;
  ma[{par, root_child}] = (dep[chi] + wei) % mod;
  dep[root_child] = (dep[chi] + wei) % mod;
}
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n + 1; i++) root[i] = i;
  for (long long i = 1; i < n + 1; i++) {
    long long k;
    cin >> k;
    if (k == 0) continue;
    for (long long j = 0; j < k; j++) {
      long long v, x;
      cin >> v >> x;
      connect(v, i, x);
    }
  }
  long long ans = 0;
  for (auto x : ma) {
    ans = (ans + (x.second) + mod) % mod;
  }
  cout << ans << endl;
  return;
}
int32_t main() {
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
