#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
int par[100100];
int weight[100100];
int norm(int a) {
  if (a >= md) a -= md;
  if (a < 0) a += md;
  return a;
}
int getpar(int a) {
  if (par[a] == a) return a;
  int pa = par[a];
  par[a] = getpar(pa);
  weight[a] = norm(weight[a] + weight[pa]);
  return par[a];
}
int main() {
  for (int i = 0; i < 100100; i++) {
    par[i] = i;
    weight[i] = 0;
  }
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a, b;
      cin >> a >> b;
      a--;
      int pa = getpar(a);
      int tw = norm(weight[a] + b);
      weight[pa] = tw;
      ans = norm(ans + tw);
      par[pa] = i;
    }
  }
  cout << ans << endl;
}
