#include <bits/stdc++.h>
int n, dsu[200000], k, v;
long long deep[200000], x, mod = 1000000007;
int get_set(int v) {
  if (v == dsu[v]) return v;
  int u = get_set(dsu[v]);
  deep[v] = (deep[v] + deep[dsu[v]]) % mod;
  return dsu[v] = u;
};
int main() {
  scanf("%d", &n);
  long long answer = 0;
  for (int i = 0; i < n; i++) {
    dsu[i] = i;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d%I64d", &v, &x);
      --v;
      int R = get_set(v);
      dsu[get_set(v)] = i;
      deep[R] = (deep[v] + x) % mod;
      answer = (answer + deep[R]) % mod;
    };
  };
  printf("%I64d\n", (answer + mod) % mod);
};
