#include <bits/stdc++.h>
using namespace std;
int trc[100005], dep[100005];
int root(int i) {
  if (i == trc[i]) return i;
  int p = root(trc[i]);
  dep[i] = (dep[i] + dep[trc[i]]) % 1000000007;
  if (dep[i] < 0) dep[i] += 1000000007;
  return trc[i] = p;
}
void input() {
  int i, k, n, x, y, p;
  int res = 0;
  scanf("%d", &n);
  for ((i) = (1); (i) <= (n); (i)++) trc[i] = i, dep[i] = 0;
  for ((i) = (1); (i) <= (n); (i)++) {
    scanf("%d", &k);
    while (k--) {
      scanf("%d %d", &x, &y);
      p = root(x);
      trc[p] = i;
      dep[p] = (dep[x] + y) % 1000000007;
      if (dep[p] < 0) dep[p] += 1000000007;
      res = (res + dep[p]) % 1000000007;
    }
  }
  printf("%d\n", res);
}
int main() {
  input();
  return 0;
}
