#include <bits/stdc++.h>
using namespace std;
int fa[100010];
long long dep[100010];
int n, m;
void make_set() {
  for (int i = 1; i <= n; i++) fa[i] = i, dep[i] = 0;
}
long long w;
int find_set(int x) {
  int tmp = fa[x];
  if (fa[x] != x) {
    fa[x] = find_set(fa[x]);
    dep[x] = (dep[x] + dep[tmp]) % 1000000007;
  }
  return fa[x];
}
void union_set(int x, int y) { fa[y] = x; }
int main() {
  int i, j, x, y;
  while (scanf("%d", &n) != EOF) {
    make_set();
    long long res = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &m);
      for (j = 0; j < m; j++) {
        scanf("%d%I64d", &y, &w);
        int fy = find_set(y);
        res = (res + dep[y] + w) % 1000000007;
        dep[fy] = (dep[y] + w) % 1000000007;
        union_set(i, fy);
      }
    }
    printf("%I64d\n", (res + 1000000007) % 1000000007);
  }
  return 0;
}
