#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10;
const long long int mod = 1e9 + 7;
const long long int inf = 1e16;
long long int dis[N];
int par[N];
int find(int u) {
  if (par[u] == u) return u;
  int t = par[u];
  par[u] = find(par[u]);
  dis[u] = (dis[u] + (dis[t] % mod)) % mod;
  return par[u];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  long long int ans = 0;
  for (int i = 0; i < n; i++) par[i] = i;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      long long int v, x;
      cin >> v >> x;
      x += mod;
      v--;
      int r = find(v);
      par[r] = i;
      dis[r] = (dis[v] % mod + x % mod) % mod;
      ans += dis[r] % mod;
      ans %= mod;
    }
  }
  cout << ans % mod << endl;
  return 0;
}
