#include <bits/stdc++.h>
using namespace std;
int n, p[111111], k, x, d;
long long v[111111];
long long ans;
void gg(int x) {
  int y = x;
  long long s = 0;
  while (p[x] != x) s += v[x], x = p[x];
  while (x != y) {
    int t = p[y], d = v[y];
    v[y] = (s % 1000000007 + 1000000007 * 1ll * 1000000007) % 1000000007;
    s -= d;
    p[y] = x;
    y = t;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) p[i] = i;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> x >> d;
      x--;
      gg(x);
      ans += v[x] + d;
      v[p[x]] = (v[x] + d + 1000000007 * 1ll * 1000000007) % 1000000007;
      p[p[x]] = i;
    }
  }
  ans += 1000000007 * 1ll * 1000000007;
  ans %= 1000000007;
  cout << (ans) << endl;
  return 0;
}
