#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
map<char, int> mi;
map<char, int> mj;
struct Point {
  double x, y;
  Point(){};
  Point(double x1, double y1) {
    x = x1;
    y = y1;
  }
};
void read(Point a) {
  double x, y;
  cin >> x >> y;
  a = Point(x, y);
}
struct Line {
  double a, b, c;
  Line(){};
  Line(Point first, Point second) {
    a = second.y - first.y;
    b = first.x - second.x;
    c = -a * second.x - b * second.y;
  }
};
const int MAXN = 1e5 + 1;
int par[MAXN], sz[MAXN];
long long path[MAXN];
const long long MOD = 1000000007ll;
long long mode(long long a) { return (a % MOD + MOD) % MOD; }
pair<int, long long> get_root(int a, long long cur) {
  if (par[a] == a) {
    path[a] = 0;
    return {a, path[a]};
  }
  auto e = get_root(par[a], cur);
  par[a] = e.first;
  path[a] = mode(path[a] + e.second);
  return make_pair(e.first, path[a]);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= MAXN; i++) par[i] = i;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    int v;
    long long x;
    for (int j = 0; j < k; j++) {
      cin >> v >> x;
      auto l = get_root(v, 0ll);
      par[l.first] = i + 1;
      path[l.first] = mode(x + l.second);
      ans = mode(ans + mode((x + l.second)));
    }
  }
  cout << mode(ans);
}
