#include <bits/stdc++.h>
using namespace std;
const int maxN = 100050, mod = 1000000007;
;
int n, ans, k;
int fa[maxN], c[maxN];
int getfa(int u) {
  if (fa[u] == u) return u;
  int t = fa[u];
  fa[u] = getfa(fa[u]);
  while (c[u] < 0) c[u] += mod;
  while (c[t] < 0) c[t] += mod;
  c[u] = (c[u] + c[t]) % mod;
  return fa[u];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    c[i] = 0;
  }
  int v, x;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d%d", &v, &x);
      int t = getfa(v);
      fa[t] = i;
      while (c[v] < 0) c[v] += mod;
      while (x < 0) x += mod;
      c[t] = (c[v] + x) % mod;
      while (c[t] < 0) c[t] += mod;
      while (ans < 0) ans += mod;
      ans = (ans + c[t]) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
