#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 100005;
int par[maxn];
long long dis[maxn];
int findset(int x) {
  int t = par[x];
  if (t != x) {
    par[x] = findset(t);
    dis[x] += dis[t];
    dis[x] %= mod;
  }
  return par[x];
}
int main() {
  int n;
  int a, b, c;
  long long res = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    scanf("%d", &a);
    while (a--) {
      scanf("%d%d", &b, &c);
      int pb = findset(b);
      par[pb] = i;
      dis[pb] = dis[b] + c;
      res += dis[pb];
      res %= mod;
    }
  }
  printf("%I64d\n", (res + mod) % mod);
}
