#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000;
const int mod = (int)1e9 + 7;
int p[maxn], W[maxn];
int n;
pair<int, int> findS(int v) {
  if (p[v] != v) {
    pair<int, int> tmp = findS(p[v]);
    p[v] = tmp.first;
    W[v] = (W[v] + tmp.second) % mod;
  }
  return make_pair(p[v], W[v]);
}
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int k;
    scanf("%d", &k);
    p[i] = i;
    W[i] = 0;
    for (int it = 0; it < k; ++it) {
      int v, x;
      scanf("%d%d", &v, &x);
      --v;
      if (x < 0) x = (x + mod) % mod;
      pair<int, int> tmp = findS(v);
      p[tmp.first] = i;
      W[tmp.first] = (tmp.second + x) % mod;
      ans = (ans + W[tmp.first]) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}
