#include <bits/stdc++.h>
using namespace std;
int g[100001];
long long d[100001];
int _find(int v) {
  if (g[v] == v)
    return v;
  else {
    int u = g[v];
    g[v] = _find(g[v]);
    d[v] = ((d[u] + d[v]) % 1000000007LL + 1000000007LL) % 1000000007LL;
    return g[v];
  }
}
int main() {
  int n;
  while (cin >> n) {
    int sol = 0;
    for (int i = 0; i < n; i++) {
      d[i] = 0;
      g[i] = i;
    }
    for (int i = 0; i < n; i++) {
      int num;
      cin >> num;
      for (int j = 0; j < num; j++) {
        int v;
        long long k;
        cin >> v >> k;
        v--;
        int root = _find(v);
        long long t = d[v] + k;
        t = (t + 1000000007LL) % 1000000007LL;
        sol += t;
        sol = (sol + 1000000007LL) % 1000000007LL;
        d[root] = t;
        g[root] = i;
      }
    }
    cout << sol << endl;
  }
  return 0;
}
