#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long cp[100010];
long long dis[100010];
const long long MOD = 1e9 + 7;
long long find(long long x) {
  if (cp[x] == x) return x;
  long long par = cp[x];
  cp[x] = find(cp[x]);
  dis[x] += dis[par];
  dis[x] = (dis[x] + MOD) % MOD;
  return cp[x];
}
void union_(long long x, long long y) { cp[find(x)] = find(y); }
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 0; i < n; ++i) cp[i] = i;
  for (long long j = 0; j < n; ++j) {
    long long k;
    cin >> k;
    for (long long i = 0; i < k; ++i) {
      long long v, x;
      cin >> v >> x;
      v--;
      long long u = find(v);
      long long d = dis[v];
      dis[u] = (d + x + MOD) % MOD;
      ans = (ans + dis[u] + MOD) % MOD;
      union_(u, j);
      find(v);
    }
  }
  cout << ans << "\n";
}
