#include <bits/stdc++.h>
using namespace std;
struct Data {
  int Root, Dist;
};
const int Mod = 1000000007;
Data P[100000];
void Root(int V) {
  if (P[V].Root == V) return;
  int U = P[V].Root;
  Root(U);
  P[V].Root = P[U].Root;
  P[V].Dist = (P[V].Dist + P[U].Dist) % Mod;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) P[i] = (Data){i, 0};
  int Ans = 0;
  for (int i = 0; i < N; i++) {
    int M;
    scanf("%d", &M);
    for (int j = 0; j < M; j++) {
      int V, W;
      scanf("%d%d", &V, &W);
      V--;
      Root(V);
      W = (W + P[V].Dist) % Mod;
      V = P[V].Root;
      P[V] = (Data){i, W};
      Ans = (Ans + W) % Mod;
    }
  }
  if (Ans < 0) Ans += Mod;
  printf("%d\n", Ans);
  return 0;
}
