#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 10;
long long par[N], dep[N];
long long getPar(long long v) {
  if (par[v] == v) return v;
  long long p = getPar(par[v]);
  dep[v] = (dep[v] + dep[par[v]]) % mod;
  par[v] = par[par[p]];
  return p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    par[i] = i;
    long long t;
    cin >> t;
    for (long long j = 0; j < t; j++) {
      long long v, w;
      cin >> v >> w;
      long long p = getPar(v);
      par[p] = i;
      dep[p] = (dep[v] + w) % mod;
      ans = (ans + dep[p]) % mod;
    }
  }
  cout << (ans + mod) % mod;
  return 0;
}
