#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int INF = 1e9 + 10;
const long long LINF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 100;
const int MN = 2e5 + 10;
const int MOD = 1e9 + 7;
int n;
int par[MN], dep[MN];
long long ans;
int root(int a) {
  if (par[a] == a) return a;
  int tmp = root(par[a]);
  dep[a] = (1ll * dep[a] + dep[par[a]]) % MOD;
  par[a] = par[par[a]];
  return tmp;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) par[i] = i;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int v, x;
      cin >> v >> x;
      --v;
      int rt = root(v);
      par[rt] = i;
      dep[rt] = (1ll * x + dep[v] + MOD) % MOD;
      ans += dep[rt] + MOD;
      ans %= MOD;
    }
  }
  cout << ans % MOD << endl;
  return 0;
}
