#include <bits/stdc++.h>
using namespace std;
const long oo = 1000000007;
long f[100005];
long long cost[100005];
long find(long now) {
  if (f[now] == now) {
    return now;
  } else {
    find(f[now]);
    cost[now] += cost[f[now]];
    f[now] = find(f[now]);
    return f[now];
  }
}
void hebing(long a, long b, long long c) {
  if (b > a) {
    f[a] = b;
    cost[a] = c;
  } else {
    f[b] = a;
    cost[b] = c;
  }
}
int main() {
  long long ans = 0;
  long long x;
  long v, n, k;
  scanf("%ld", &n);
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    cost[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%ld", &k);
    while (k--) {
      scanf("%ld%I64d", &v, &x);
      find(v);
      x = (x + cost[v] + oo) % oo;
      while (x < 0) x = x + oo;
      ans = (ans + x) % oo;
      hebing(find(i), find(v), x);
    }
  }
  printf("%I64d\n", ans);
}
