#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[100100];
pair<long long int, long long int> par[100100];
int n, k;
long long int base = 1000000007;
long long int mod(long long int x) {
  if (x >= 0) return x % base;
  if (x % base == 0) return 0;
  return (base + x % base);
}
pair<long long int, long long int> dsufind(int x) {
  if (par[x].first == x) return par[x];
  pair<long long int, long long int> z = dsufind(par[x].first);
  par[x] = make_pair(z.first, mod((long long int)z.second + par[x].second));
  return par[x];
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> k;
    par[i] = make_pair(i, 0);
    for (int j = 1; j <= k; j++) {
      int vv, x;
      cin >> vv >> x;
      pair<int, int> e = dsufind(vv);
      v[e.first].push_back(mod((long long int)e.second + x));
      par[e.first] = make_pair(i, mod((long long int)e.second + x));
    }
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      ans = mod((long long int)ans + v[i][j]);
    }
  }
  cout << ans << endl;
}
