#include <bits/stdc++.h>
using namespace std;
long long pre[100005], c[100005], mod = 1e9 + 7;
long long find(long long x) {
  if (x != pre[x]) {
    long long t = pre[x];
    pre[x] = find(t);
    c[x] = (c[x] + c[t]) % mod;
  }
  return pre[x];
}
int main() {
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    pre[i] = i;
  }
  for (long long i = 1; i <= n; i++) {
    long long num;
    cin >> num;
    for (long long j = 1; j <= num; j++) {
      long long v, x;
      cin >> v >> x;
      long long now = find(v);
      c[now] = (c[v] + x) % mod;
      pre[now] = i;
      ans = (ans + c[now]) % mod;
    }
  }
  cout << (ans % mod + mod) % mod << endl;
}
