#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > p(100000);
int sum;
void make_set(int x) { p[x] = make_pair(x, 0); }
pair<int, int> find_set(int x) {
  if (p[x].first != x) {
    int len = p[x].second;
    p[x] = find_set(p[x].first);
    p[x].second = (p[x].second + len) % 1000000007;
  }
  return p[x];
}
void union_sets(int a, int b, int len) {
  pair<int, int> y;
  y = find_set(b);
  p[y.first] = make_pair(a, (y.second + len) % 1000000007);
  sum += (p[y.first].second) % 1000000007;
  sum = sum % 1000000007;
}
void std_io() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void task_io() {
  freopen("task.in", "r", stdin);
  freopen("task.out", "w", stdout);
}
void solve() {
  int n, i, j, k, v, x;
  cin >> n;
  for (i = 0; i < n; i++) {
    make_set(i);
    cin >> k;
    for (j = 0; j < k; j++) {
      cin >> v >> x;
      v--;
      union_sets(i, v, x);
    }
  }
  if (sum < 0)
    cout << sum + 1000000007;
  else
    printf("%d\n", sum % 1000000007);
}
int main() {
  solve();
  return 0;
}
