#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int root[100000], depth[100000], edge[100000];
int update(int node, int& dep, int sum, int x, int new_root, int& new_edge) {
  if (root[node] == node) {
    root[node] = new_root;
    depth[node] = (sum + x) % MOD;
    edge[node] = depth[node];
    new_edge = edge[node];
    dep = depth[node];
    return new_root;
  }
  int d;
  root[node] =
      update(root[node], d, (sum + depth[node]) % MOD, x, new_root, new_edge);
  depth[node] = (d + depth[node]) % MOD;
  dep = depth[node];
  return root[node];
}
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    root[i] = i;
    depth[i] = 0;
    int e;
    cin >> e;
    while (e--) {
      int v, x;
      cin >> v >> x;
      v--;
      int new_edge;
      root[v] = update(v, depth[v], 0, x, i, new_edge);
      ans = (ans + new_edge) % MOD;
    }
  }
  cout << (ans + MOD) % MOD << endl;
}
