#include <bits/stdc++.h>
using namespace std;
const int max_N = 100000 + 20;
const int MOD = 1000000007;
int root[max_N], depth[max_N];
int findroot(int v) {
  if (root[v] != root[root[v]]) {
    int x = findroot(root[v]);
    depth[v] = (depth[v] + depth[root[v]]) % MOD;
    root[v] = x;
  }
  return root[v];
}
int main() {
  ios::sync_with_stdio(false);
  int n, k, v, x, ans(0);
  cin >> n;
  for (int i = 0; i < n; i++) root[i] = i;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < 2 * k; j += 2) {
      cin >> v >> x;
      v--;
      int r = findroot(v);
      x += MOD, x %= MOD;
      int y = (depth[v] + x) % MOD;
      ans = (ans + y) % MOD;
      depth[v] = (depth[v] + y) % MOD;
      depth[root[v]] = y;
      root[root[v]] = i, root[v] = i;
    }
  }
  cout << ans << endl;
  return 0;
}
