#include <bits/stdc++.h>
using namespace std;
long long d[100000 + 10];
int p[100000 + 10];
void makeSet(int x) {
  p[x] = x;
  d[x] = 0;
}
int find(int x) {
  if (p[x] != x) {
    int f = find(p[x]);
    d[x] = (d[x] + d[p[x]]) % 1000000007;
    p[x] = f;
  }
  return p[x];
}
bool solve() {
  bool ret = false;
  int n;
  if (cin >> n) {
    ret = true;
    for (int(l) = 0; (l) < (int)(n); ++(l)) {
      makeSet(l + 1);
    }
    int ans = 0;
    for (int(l) = 0; (l) < (int)(n); ++(l)) {
      int k;
      scanf("%d", &k);
      for (int(i) = 0; (i) < (int)(k); ++(i)) {
        int v, x;
        scanf("%d%d", &v, &x);
        int f = find(v);
        p[f] = l + 1;
        d[f] = (d[v] + x) % 1000000007;
        ans = (ans + d[f]) % 1000000007;
        if (ans < 0) ans += 1000000007;
      }
    }
    cout << ans << endl;
  }
  return ret;
}
int main() {
  while (solve())
    ;
  return 0;
}
