#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 1e5 + 10;
int f[N];
long long w[N];
void Mod(long long &a) {
  while (a < 0) a += 1000000007;
  while (a >= 1000000007) a -= 1000000007;
}
int find(int a) {
  if (a == f[a]) {
    return a;
  }
  int t = f[a];
  f[a] = find(f[a]);
  w[a] += w[t];
  Mod(w[a]);
  return f[a];
}
int main() {
  int m, i, j, k, r, n;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) f[i] = i, w[i] = 0;
    long long ans = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &k);
      while (k--) {
        int a;
        long long b;
        scanf("%d%I64d", &a, &b);
        int fa = find(a);
        f[fa] = i;
        Mod(b);
        long long sum = w[a] + b;
        Mod(sum);
        ans += sum;
        Mod(ans);
        w[fa] = sum;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
