#include <bits/stdc++.h>
using namespace std;
int n;
int pai[100500], c[100500];
void find(int u, int &p, int &d) {
  if (pai[u] == u) {
    p = u;
    d = 0;
    return;
  }
  find(pai[u], p, d);
  pai[u] = p;
  c[u] = (((d + c[u]) % 1000000007) + 1000000007) % 1000000007;
  d = c[u];
}
int main() {
  scanf("%d", &n);
  int res = 0;
  for (int i = 0; i < n; i++) {
    int k;
    scanf("%d", &k);
    pai[i] = i;
    c[i] = 0;
    int u, x, p, d;
    for (int j = 0; j < k; j++) {
      scanf("%d %d", &u, &x);
      u--;
      find(u, p, d);
      pai[p] = i;
      c[p] = (((d + x) % 1000000007) + 1000000007) % 1000000007;
      res = (res + c[p]) % 1000000007;
    }
  }
  printf("%d\n", res);
  return 0;
}
