#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int md = 1e9 + 7;
int fa[MAXN];
long long int dep[MAXN], edge[MAXN];
int n;
int find(int x) {
  if (fa[x] == x) {
    return x;
  }
  int father = fa[x];
  fa[x] = find(fa[x]);
  dep[x] += dep[father];
  dep[x] %= md;
  return fa[x];
}
void merge(int x, int y, long long int w) {
  int fx = find(x);
  dep[fx] = w + dep[x];
  edge[fx] = dep[fx];
  fa[fx] = y;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < MAXN; i++) fa[i] = i, dep[i] = 0, edge[i] = 0;
    int k;
    int u;
    long long int w;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &k);
      for (int t = 0; t < k; t++) {
        scanf("%d%I64d", &u, &w);
        merge(u, i, w);
      }
    }
    long long int ans = 0;
    for (int i = 1; i <= n; i++) {
      ans += edge[i];
      ans %= md;
    }
    while (ans < 0) ans += md;
    cout << ans % md << endl;
  }
  return 0;
}
