#include <bits/stdc++.h>
using namespace std;
int tree[110000];
int cc[110000];
int find(int x) {
  if (x == tree[x]) return x;
  int fa = tree[x];
  tree[x] = find(tree[x]);
  cc[x] = (cc[x] + cc[fa]) % 1000000007;
  return tree[x];
}
int main() {
  int i, j, h;
  int T, n, m;
  int a, b, c;
  int k, v, x;
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      tree[i] = i;
      cc[i] = 0;
    }
    long long ans = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &k);
      for (j = 1; j <= k; j++) {
        scanf("%d %d", &v, &x);
        int fa = find(i);
        int fb = find(v);
        int sum = cc[v] + x;
        if (fa != fb) {
          tree[fb] = tree[fa];
          cc[fb] = (cc[i] + sum) % 1000000007;
        }
        ans += sum;
        while (ans < 0) ans += 1000000007;
        ans %= 1000000007;
      }
    }
    printf("%I64d\n", ans);
  }
}
