#include <bits/stdc++.h>
using namespace std;
const int MAX = 100100;
const int MOD = 1000000007;
int parent[MAX], dpth[MAX], n, ans;
void find(int v) {
  if (parent[v] == v) return;
  find(parent[v]);
  dpth[v] = (dpth[v] + dpth[parent[v]]) % MOD;
  parent[v] = parent[parent[v]];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    parent[i] = i;
    int k;
    scanf("%d", &k);
    while (k--) {
      int v, x;
      scanf("%d%d", &v, &x);
      find(v);
      x = (x + dpth[v]) % MOD;
      v = parent[v];
      parent[v] = i;
      dpth[v] = x;
      ans = (ans + x) % MOD;
    }
  }
  printf("%d\n", (ans + MOD) % MOD);
  return 0;
}
