#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
const int N = 1e5 + 1;
int par[N], dis[N];
void update(int v) {
  if (par[v] == v) return;
  update(par[v]);
  dis[v] = (dis[v] + dis[par[v]]) % Mod;
  par[v] = par[par[v]];
}
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    par[i] = i;
    int q;
    cin >> q;
    while (q--) {
      int v, x;
      cin >> v >> x;
      v--;
      update(v);
      int w = (dis[v] + x) % Mod;
      ans = (ans + w) % Mod;
      dis[par[v]] = w;
      par[par[v]] = i;
    }
  }
  ans = (ans + Mod) % Mod;
  cout << ans << endl;
}
