#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int fa[100005];
long long d[100005];
int find(int x) {
  if (x == fa[x]) return x;
  int u = fa[x];
  fa[x] = find(u);
  d[x] = ((d[x] + d[u]) % mod + mod) % mod;
  return fa[x];
}
int main() {
  int n, i, j, k, x, fx;
  long long ans = 0, y;
  cin >> n;
  for (i = 1; i <= n; i++) fa[i] = i, d[i] = 0;
  for (i = 1; i <= n; i++) {
    cin >> k;
    while (k--) {
      cin >> x >> y;
      fx = find(x);
      ans += d[x] + y, ans %= mod, ans = (ans + mod) % mod;
      d[fx] = ((d[x] + y) % mod + mod) % mod;
      fa[fx] = i;
    }
  }
  cout << ans << endl;
  return 0;
}
