#include <bits/stdc++.h>
using namespace std;
int depth[100005], head[100005];
void init() {
  for (int i = 0; i < 100005; i++) {
    head[i] = i;
    depth[i] = 0;
  }
}
int tmp[100005];
int unionFind(int n) {
  int it = 0;
  while (n != head[n]) {
    tmp[it++] = n;
    n = head[n];
  }
  tmp[it] = n;
  for (int i = it - 1; i >= 0; i--) {
    head[tmp[i]] = n;
    depth[tmp[i]] = (0LL + depth[tmp[i]] + depth[tmp[i + 1]]) % 1000000007;
  }
  return n;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    init();
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int k;
      scanf("%d", &k);
      while (k--) {
        int a, b;
        scanf("%d %d", &a, &b);
        int c = unionFind(a);
        head[c] = i;
        depth[c] = (0LL + depth[a] + b + 1000000007) % 1000000007;
        ans = (0LL + ans + depth[c] + 1000000007) % 1000000007;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
