#include <bits/stdc++.h>
using namespace std;
int p[100100];
int sumtree[100100];
int sum[100100];
int find(int x) {
  if (x == p[x]) return x;
  return p[x] = find(p[x]);
}
void join(int x, int y) {
  x = find(x);
  y = find(y);
  if (rand() & 1)
    p[x] = y;
  else
    p[y] = x;
}
vector<vector<pair<int, int> > > g;
int mod = 1000000007;
int num[100100];
map<int, int> mm[100100];
int add[100100];
int main() {
  int n;
  scanf("%d", &n);
  g.resize(n);
  int res = 0;
  int last = 0;
  for (int i = (0); i < (n); ++i) {
    int k;
    scanf("%d", &k);
    if (k == 0) {
      mm[last][i] = 0;
      num[i] = last;
      last++;
      continue;
    }
    for (int j = (0); j < (k); ++j) {
      int v, x;
      scanf("%d%d", &v, &x);
      while (x < 0) x += mod;
      g[i].push_back(make_pair(v - 1, x));
    }
    int max1 = -1, v = -1, ver = -1;
    for (int j = (0); j < (k); ++j) {
      int c = g[i][j].first;
      if ((int)mm[num[c]].size() > max1) {
        max1 = mm[num[c]].size();
        v = num[c];
        ver = j;
      }
    }
    swap(g[i][ver], g[i][0]);
    int val = g[i][0].second;
    val += mm[v][g[i][0].first];
    if (val >= mod) val -= mod;
    val += add[v];
    if (val >= mod) val -= mod;
    res += val;
    if (res >= mod) res -= mod;
    add[v] += val;
    if (add[v] >= mod) add[v] -= mod;
    for (int j = (1); j < (k); ++j) {
      int c = num[g[i][j].first];
      int val = mm[c][g[i][j].first] + add[c];
      if (val >= mod) val -= mod;
      res += val;
      int x = g[i][j].second;
      if (res >= mod) res -= mod;
      res += x;
      if (res >= mod) res -= mod;
      for (map<int, int>::iterator it = mm[c].begin(); it != mm[c].end();
           ++it) {
        int nv = it->first;
        int nval = it->second + val;
        if (nval >= mod) nval -= mod;
        nval += x;
        if (nval >= mod) nval -= mod;
        nval += add[c];
        if (nval >= mod) nval -= mod;
        nval -= add[v];
        if (nval < 0) nval += mod;
        mm[v][nv] = nval;
        num[nv] = v;
      }
    }
    int q = -add[v];
    while (q < 0) q += mod;
    mm[v][i] = q;
    num[i] = v;
  }
  printf("%d\n", res);
  return 0;
}
