#include <bits/stdc++.h>
using namespace std;
void run();
int main() {
  ;
  ios::sync_with_stdio(false);
  run();
}
long long const l = 100000;
long long const mod = 1000000007;
struct LinkCut {
  LinkCut *p, *l, *r;
  long long weight;
  long long sum;
  inline LinkCut(LinkCut* p = nullptr) : p(p) { l = r = nullptr; }
  inline bool root() { return not p or p->l != this and p->r != this; }
  inline void push() { sum = weight + (l ? l->sum : 0) + (r ? r->sum : 0); }
  inline void increase(long long by) {
    splay();
    (weight += by) %= mod;
    push();
  }
  inline void rot(LinkCut* LinkCut::*a, LinkCut* LinkCut::*b) {
    if (not root()) (p->l == this ? p->l : p->r) = (this->*a);
    (this->*a)->p = p, p = (this->*a);
    (this->*a) = (p->*b), (p->*b) = this;
    if (this->*a) (this->*a)->p = this;
    if (l) l->push();
    if (r) r->push();
    push();
  }
  inline void rotate() {
    if (p->l == this)
      p->rot(&LinkCut::l, &LinkCut::r);
    else
      p->rot(&LinkCut::r, &LinkCut::l);
  }
  inline void splay() {
    push();
    while (not root()) {
      if (not p->root()) p->p->push();
      p->push();
      push();
      if (not p->root())
        ((p->l == this) == (p->p->l == p) ? p : this)->rotate();
      rotate();
    }
    push();
  }
  inline void link(LinkCut* x) {
    splay();
    p = x;
    p->splay();
  }
  inline void expose() {
    for (LinkCut *i = this, *j = nullptr; i; j = i, i = i->p) {
      i->splay();
      i->l = j;
      i->push();
    }
    splay();
  }
  inline long long depth() {
    splay();
    return sum;
  }
  inline LinkCut* findroot() {
    expose();
    LinkCut* x = this;
    while (x->r) x = x->r, x->push();
    return x;
  }
};
LinkCut tree[l];
long long w[l];
void run() {
  long long res = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      long long v, x;
      cin >> x >> v;
      --x;
      while (v < 0) v += mod;
      long long plus = tree[x].findroot()->depth();
      long long y = tree[x].findroot() - tree;
      tree[y].link(tree + i);
      tree[y].increase(v + plus);
      (res += v + plus) %= mod;
    }
  }
  cout << res << endl;
}
