#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 1e5 + 15;
long long ans;
pair<int, int> par[maxn];
int get_par(int x) {
  if (par[x].first == 0) return x;
  int y = get_par(par[x].first);
  par[x].second += par[par[x].first].second;
  par[x].second %= mod;
  par[x].first = y;
  return y;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int v, x;
      cin >> v >> x;
      int u = get_par(v);
      par[u].first = i;
      par[u].second = x + par[v].second;
      par[u].second %= mod;
      ans += par[u].second;
      ans %= mod;
      if (ans <= 0) ans += mod;
    }
  }
  cout << ans;
  return 0;
}
