#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
const int MOD = INF + 7;
int n;
pair<int, int> l[MAXN];
pair<int, int> leader(int v) {
  int oldv = v;
  vector<pair<int, int> > path;
  while (l[v].first != v) {
    path.push_back(make_pair(v, l[v].second));
    v = l[v].first;
  }
  for (int i = (int)(path.size()) - 1; i >= 0; i--) {
    int u = path[i].first;
    l[u].second = (l[l[u].first].second + path[i].second) % MOD;
    l[u].first = v;
  }
  return l[oldv];
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++) l[i] = make_pair(i, 0);
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int k;
    scanf("%d", &k);
    for (int j = 0; j < (int)(k); j++) {
      int v, x;
      scanf("%d%d", &v, &x);
      x = ((x % MOD) + MOD) % MOD;
      pair<int, int> u = leader(v - 1);
      l[u.first] = make_pair(i, (u.second + x) % MOD);
      ans = (l[u.first].second + ans) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
