#include <bits/stdc++.h>
int n, k, p[100005], w[100005], num, v, x, ac, part;
using namespace std;
void open() {
  freopen("e.in", "r", stdin);
  freopen("e.out", "w", stdout);
}
void close() {
  fclose(stdin);
  fclose(stdout);
}
int parent(int x) {
  if (x == p[x]) return x;
  int y = p[x];
  int z = parent(p[x]);
  w[x] += w[y];
  w[x] = w[x] % 1000000007;
  p[x] = z;
  return z;
}
int main() {
  scanf("%d", &n);
  num = 0;
  ac = 0;
  while (n--) {
    ++num;
    p[num] = num;
    w[num] = 0;
    scanf("%d", &k);
    while (k--) {
      scanf("%d%d", &v, &x);
      part = parent(v);
      p[part] = num;
      w[part] = (x + w[v]) % 1000000007;
      ac = (ac + w[part]) % 1000000007;
      if (ac < 0) ac += 1000000007;
    }
  }
  printf("%d\n", ac);
  close();
  return 0;
}
