#include <bits/stdc++.h>
const int mod = 1000000007;
struct uinon_set {
  int father[100003], n, value[100003];
  int ans;
  void init() {
    ans = 0;
    for (int i = 1; i <= n; i++) {
      father[i] = i;
      value[i] = 0;
    }
    return;
  }
  int getfather(int i) {
    if (father[i] == i) return i;
    int tans = getfather(father[i]);
    value[i] = (value[i] + value[father[i]]) % mod;
    return father[i] = tans;
  }
  void insert(int root, int i, int xi) {
    int temp, tmp = getfather(root);
    temp = (value[root] + xi) % mod;
    father[tmp] = i;
    value[tmp] = temp;
    ans = (ans + temp) % mod;
    return;
  }
} set;
int main() {
  int n, t, x, y, i, j;
  scanf("%d", &n);
  set.n = n;
  set.init();
  for (i = 1; i <= n; i++) {
    scanf("%d", &t);
    for (j = 0; j < t; j++) {
      scanf("%d%d", &x, &y);
      set.insert(x, i, y);
    }
  }
  printf("%d\n", (set.ans + mod) % mod);
  return 0;
}
