#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int n, fa[N];
long long ans, val[N];
int getfa(int x) {
  if (fa[x] == x) return x;
  int f = getfa(fa[x]);
  val[x] = (val[x] + val[fa[x]] + mod) % mod;
  fa[x] = f;
  return f;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int v, x;
      scanf("%d%d", &v, &x);
      int u = getfa(v);
      fa[u] = i;
      val[u] = (x + val[v] + mod) % mod;
      ans = (ans + val[u]) % mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
