#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10, INF = INT_MAX, MOD = 1e9 + 7;
int par[MAXN];
long long dep[MAXN];
int find(int v) {
  if (par[v] == -1) return v;
  int t = find(par[v]);
  dep[v] = (dep[par[v]] + dep[v] + MOD) % MOD;
  return par[v] = t;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long ans = 0;
  memset(par, -1, sizeof par);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int v;
      long long x;
      cin >> v >> x;
      v--;
      int u = find(v);
      dep[u] = (dep[v] + x + MOD) % MOD;
      par[u] = i;
      ans = (ans + dep[u] + MOD) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
