#include <bits/stdc++.h>
const int M = 1e9 + 7, N = 1e5 + 5;
int p[N], l[N], n, m, v, x, i, j, r;
int f(int x) {
  if (p[x] == x) return x;
  int t = p[x];
  p[x] = f(p[x]);
  l[x] = (l[x] + l[t]) % M;
  return p[x];
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) p[i] = i;
  for (i = 1; i <= n; i++)
    for (scanf("%d", &m); m--;) {
      scanf("%d%d", &v, &x);
      int t = f(v);
      r = (r + 1LL * l[v] + x) % M;
      p[t] = i;
      l[t] = (l[v] + x) % M;
    }
  printf("%d", (r + M) % M);
}
