#include <bits/stdc++.h>
using namespace std;
int dsu[100500], depth[100500], res[100500];
int dsu_search(int v) {
  int t = v, tmp, t1;
  long long h = 0;
  while (dsu[v] != v) {
    h += depth[v];
    while (h >= 1000000007) h -= 1000000007;
    v = dsu[v];
  }
  while (t != v) {
    tmp = t;
    t = dsu[t];
    dsu[tmp] = v;
    t1 = depth[tmp];
    depth[tmp] = h;
    h -= t1;
    while (h < 0) h += 1000000007;
  }
  return v;
}
void dsu_union(int v1, int v2, int x1) {
  int r1 = dsu_search(v1);
  dsu[r1] = v2;
  res[r1] = depth[r1] = (depth[v1] + x1 + 0LL) % 1000000007;
}
int main() {
  int n, k, j, i, v, x;
  cin >> n;
  memset(depth, 0, sizeof(depth));
  memset(res, 0, sizeof(res));
  for (i = 0; i <= n; ++i) dsu[i] = i;
  for (i = 1; i <= n; ++i) {
    cin >> k;
    for (j = 0; j < k; ++j) {
      cin >> v >> x;
      if (x < 0) {
        int t = -x / 1000000007;
        x += t * 1000000007;
        while (x < 0) x += 1000000007;
        while (x >= 1000000007) x -= 1000000007;
      }
      dsu_union(v, i, x);
    }
  }
  long long r = 0;
  for (i = 1; i <= n; ++i) r = (r + res[i]) % 1000000007;
  cout << r;
  return 0;
}
