#include <bits/stdc++.h>
using namespace std;
int n, k, v, x, fa[100005];
long long ans, dep[100005] = {0};
void findfa(int x) {
  long long sum = 0;
  int now = x, tmp;
  while (fa[x] != x) sum = (sum + dep[x]) % 1000000007, x = fa[x];
  while (now != x) {
    tmp = fa[now];
    (sum -= dep[now]) %= 1000000007;
    (dep[now] += sum) %= 1000000007;
    fa[now] = x;
    now = tmp;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d%d", &v, &x);
      findfa(v);
      (ans = ans + x + dep[v]) %= 1000000007;
      dep[fa[v]] = x + dep[v];
      fa[fa[v]] = i;
    }
  }
  cout << (ans % 1000000007 + 1000000007) % 1000000007 << endl;
  return 0;
}
