#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int mod = 1000000007;
int fa[MAXN], n;
long long depth[MAXN];
long long tot = 0;
int getfa(int x) {
  if (fa[x] == x) return fa[x];
  int temp = fa[x];
  fa[x] = getfa(fa[x]);
  depth[x] += depth[temp];
  return fa[x];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) fa[i] = i, depth[i] = 0;
  tot = 0;
  for (int i = 1; i <= n; i++) {
    int k, x, v;
    scanf("%d", &k);
    long long tmp = 0;
    while (k--) {
      scanf("%d%d", &x, &v);
      int root = getfa(x);
      fa[root] = i;
      tot += depth[x] + v;
      depth[root] = ((depth[x] + v) % mod + mod) % mod;
    }
  }
  cout << (tot % mod + mod) % mod << endl;
  return 0;
}
