#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10, MOD = 1000000007;
long long rt[MAXN], w[MAXN];
long long FindW(int v) {
  if (rt[v] == v) return 0;
  return w[v] = w[v] + FindW(rt[v]);
}
long long FindRT(int v) {
  if (rt[v] == v) return v;
  return rt[v] = FindRT(rt[v]);
}
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    rt[i] = i;
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      long long v, x;
      cin >> v >> x;
      v--;
      long long e = FindW(v);
      long long u = FindRT(v);
      w[u] = x + e;
      rt[u] = i;
      w[u] %= MOD;
      sum += w[u];
      sum %= MOD;
    }
  }
  if (sum < 0) sum += MOD;
  cout << sum << endl;
}
