#include <bits/stdc++.h>
using namespace std;
struct vertex {
  int c;
  int sum;
};
vector<vertex> graph;
const int M = 1e9 + 7;
long long r;
int root(int x) {
  if (graph[x].c == x) {
    return x;
  } else {
    int u = graph[x].c;
    graph[x].c = root(graph[x].c);
    graph[x].sum = (graph[x].sum + graph[u].sum) % M;
    return graph[x].c;
  }
}
int main() {
  int n, k;
  cin >> n;
  graph.resize(n);
  for (int i = 0; i < n; i++) {
    graph[i].c = i;
    for (cin >> k; k--;) {
      int v, x;
      cin >> v >> x;
      v--;
      int t = root(v);
      r = (r + graph[v].sum + x) % M;
      graph[t].c = i;
      graph[t].sum = (graph[v].sum + x) % M;
    }
  }
  cout << (r + M) % M;
}
