#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const maxn = 100005;
int par[maxn];
int sum[maxn];
int const mod = 1e9 + 7;
inline void safe_add(int& x, const int y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline int fnd(const int x) {
  if (par[x] == x) return x;
  int p = fnd(par[x]);
  safe_add(sum[x], sum[par[x]]);
  par[x] = p;
  return p;
}
int main() {
  cout << fixed << setprecision(15);
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  iota(begin(par), end(par), 0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int v, x;
      cin >> v >> x;
      while (x < 0) x += mod;
      while (x >= mod) x -= mod;
      int pv = fnd(v);
      int cur = sum[v];
      safe_add(cur, x);
      safe_add(ans, cur);
      safe_add(sum[pv], cur);
      par[pv] = i;
    }
  }
  cout << ans << endl;
}
