#include <bits/stdc++.h>
using namespace std;
int trc[100005], dep[100005];
pair<int, int> qr(int i) {
  if (i == trc[i]) return make_pair(i, 0);
  pair<int, int> p = qr(trc[i]);
  trc[i] = p.first;
  dep[i] = (p.second + dep[i]) % 1000000007;
  if (dep[i] < 0) dep[i] += 1000000007;
  return make_pair(p.first, dep[i]);
}
void input() {
  int i, k, n, x, y;
  int res = 0;
  pair<int, int> p;
  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 = qr(x);
      p.second = (p.second + y) % 1000000007;
      if (p.second < 0) p.second += 1000000007;
      trc[p.first] = i;
      dep[p.first] = p.second;
      res = (res + p.second) % 1000000007;
    }
  }
  printf("%d\n", res);
}
int main() {
  input();
  return 0;
}
