#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 * 1000 + 10;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long Ans;
struct DJ {
  int Par[MAX_N];
  long long Depth[MAX_N];
  DJ() {
    for (int i = 0; i < MAX_N; i++) Par[i] = i, Depth[i] = 0;
  }
  void make_set(int x) { Par[x] = x, Depth[x] = 0; }
  int find_set(int v) {
    if (Par[v] == v) return v;
    long long Temp = Par[v];
    Par[v] = find_set(Par[v]);
    Depth[v] = (Depth[v] + Depth[Temp]) % MOD;
    return Par[v];
  }
  void merge(int u, int v, long long x) {
    find_set(u);
    long long Temp = Depth[u];
    u = find_set(u);
    v = find_set(v);
    if (u == v) return;
    Par[u] = v;
    Depth[u] = (Temp + x) % MOD;
    Ans = (Ans + Depth[u]) % MOD;
  }
} MYDJ;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    long long K;
    cin >> K;
    MYDJ.make_set(i);
    for (int j = 0; j < K; j++) {
      long long v, x;
      cin >> v >> x;
      MYDJ.merge(v, i, x);
    }
  }
  cout << ((Ans % MOD) + MOD) % MOD << endl;
  return 0;
}
