#include <bits/stdc++.h>
using namespace std;
int parent[100010];
long long cost[100010];
int p[100010];
long long c[100010];
pair<int, long long> root(int x) {
  if (p[x] != x) {
    pair<int, long long> tmp = root(p[x]);
    p[x] = tmp.first;
    c[x] = (c[x] + tmp.second) % 1000000007ll;
  }
  return make_pair(p[x], c[x]);
}
int main(void) {
  int N, i, j, K, v;
  long long x;
  cin >> N;
  for ((i) = 0; (i) < (int)(N); (i)++) parent[i] = p[i] = i;
  for ((i) = 0; (i) < (int)(N); (i)++) {
    cin >> K;
    for ((j) = 0; (j) < (int)(K); (j)++) {
      cin >> v >> x;
      x = (x % 1000000007ll + 1000000007ll) % 1000000007ll;
      v--;
      pair<int, long long> tmp = root(v);
      parent[tmp.first] = p[tmp.first] = i;
      cost[tmp.first] = c[tmp.first] = (tmp.second + x) % 1000000007ll;
    }
  }
  long long ans = 0;
  for ((i) = 0; (i) < (int)(N); (i)++)
    if (parent[i] != i) ans = (ans + cost[i]) % 1000000007ll;
  cout << ans << endl;
  return 0;
}
