#include <bits/stdc++.h>
using namespace std;
int x, n, k, y, p[1000005], d[1000005], ans;
int find(int x) {
  if (x != p[x]) {
    int fx = p[x];
    p[x] = find(p[x]);
    d[x] = (d[x] + d[fx]) % 1000000007;
  }
  return p[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    if (k) {
      for (int j = 0; j < k; j++) {
        scanf("%d%d", &x, &y);
        find(x);
        d[p[x]] = (d[x] + y) % 1000000007;
        ans = (ans + d[p[x]]) % 1000000007;
        p[p[x]] = i;
      }
    }
  }
  printf("%d\n", (ans + 1000000007) % 1000000007);
  return 0;
}
