#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 3;
const int MOD = (int)1e9 + 7;
int fa[MAXN];
long long dis[MAXN];
int find_fa(int x) {
  if (fa[x] == x) return x;
  int pa = fa[x];
  fa[x] = find_fa(fa[x]);
  dis[x] += dis[pa];
  return fa[x];
}
inline void UP(long long &x) { x = (x % MOD + MOD) % MOD; }
void init(int n) {
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    dis[i] = 0;
  }
}
void solve(int n) {
  long long ans = 0LL;
  init(n);
  for (int j = 1, num; j <= n; j++) {
    scanf("%d", &num);
    for (int i = 1, v, x; i <= num; i++) {
      scanf("%d %d", &v, &x);
      int pa = find_fa(v);
      fa[pa] = j;
      dis[pa] = dis[v] + x;
      UP(dis[pa]);
      ans += dis[pa];
      UP(ans);
    }
  }
  printf("%d\n", (int)ans);
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  solve(n);
  return 0;
}
