#include <bits/stdc++.h>
std::pair<int, int> mp(int a, int b) { return std::make_pair(a, b); }
struct dat {
  int d, a, b;
  dat() { d = a = b = 0; }
  dat(int _d, int _a, int _b) { d = _d, a = _a, b = _b; }
};
int n;
int deg[100010];
std::vector<dat> edg[100010];
int fat[100010];
int T, in[100010], out[100010], vis[100010];
int zkw[(1 << 18) * 2];
int fa(int now) {
  if (fat[now] == now) return now;
  return fat[now] = fa(fat[now]);
}
void dfs(int now, int fa) {
  ++T;
  in[now] = T, vis[now] = 1;
  for (int i = 0; i < edg[now].size(); ++i) {
    int ne = edg[now][i].b;
    if (ne == fa || vis[ne] == 1) continue;
    dfs(ne, now);
  }
  ++T;
  out[now] = T;
}
void update(int le, int ri, int val) {
  le = le + (1 << 18) - 1, ri = ri + (1 << 18) + 1;
  for (; le ^ ri ^ 1; le >>= 1, ri >>= 1) {
    if (~le & 1) {
      int p = le ^ 1;
      zkw[p] += val;
      if (zkw[p] >= 1000000007) zkw[p] -= 1000000007;
    }
    if (ri & 1) {
      int p = ri ^ 1;
      zkw[p] += val;
      if (zkw[p] >= 1000000007) zkw[p] -= 1000000007;
    }
  }
}
int query(int now) {
  int r = 0;
  for (now += (1 << 18); now > 0; now >>= 1) {
    r += zkw[now];
    if (r >= 1000000007) r -= 1000000007;
  }
  return r;
}
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) fat[i] = i;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &deg[i]);
    for (int j = 0, a, b; j < deg[i]; ++j) {
      scanf("%d%d", &a, &b);
      if (b < 0) b += 1000000007;
      edg[i].push_back(dat(b, a, fa(a)));
      int t = fa(a);
      fat[t] = i;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0 && fat[i] == i) dfs(i, 0);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < edg[i].size(); ++j) {
      int ne = edg[i][j].a, nef = edg[i][j].b;
      int t = query(in[ne]) + edg[i][j].d;
      if (t >= 1000000007) t -= 1000000007;
      ans += t;
      if (ans >= 1000000007) ans -= 1000000007;
      update(in[nef], out[nef], t);
    }
  }
  printf("%d\n", ans);
  return 0;
}
