#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int root[100010];
long long peso[100010];
void scopri(int x) {
  if (root[x] == x) return;
  scopri(root[x]);
  peso[x] = (peso[x] + peso[root[x]]) % MOD;
  root[x] = root[root[x]];
}
int main() {
  int N;
  cin >> N;
  long long res = 0;
  for (int v = 1; v <= N; v++) {
    root[v] = v;
    peso[v] = 0;
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int u;
      long long p;
      cin >> u >> p;
      scopri(u);
      res = (res + p + peso[u]) % MOD;
      peso[root[u]] = (p + peso[u]) % MOD;
      root[root[u]] = v;
    }
  }
  if (res < 0) res += MOD;
  cout << res;
}
