#include <bits/stdc++.h>
using namespace std;
int root[100010];
long long depth[100010];
long long c[100010];
int parent[100010];
int main() {
  memset(root, 0, sizeof(root));
  memset(depth, 0, sizeof(depth));
  int N;
  cin >> N;
  for (int i = (1); i <= (N); i++) {
    root[i] = i;
    depth[i] = 0;
    c[i] = 0;
    parent[i] = i;
    int k;
    cin >> k;
    for (int j = 0; j < (k); j++) {
      int v;
      long long x;
      cin >> v >> x;
      long long sum = 0;
      int r = v;
      while (root[r] != r) {
        sum += depth[r];
        sum %= 1000000007ll;
        r = root[r];
      }
      c[r] = depth[r] = (sum + x + 1000000007ll) % 1000000007ll;
      root[r] = parent[r] = i;
      sum *= 2;
      sum += x;
      sum = (sum + 1000000007ll) % 1000000007ll;
      r = v;
      while (root[r] != r) {
        int old_depth = depth[r];
        int j = root[r];
        depth[r] = sum;
        root[r] = i;
        sum -= old_depth;
        sum += 1000000007ll;
        sum %= 1000000007ll;
        r = j;
      }
    }
  }
  long long ans = 0;
  for (int i = (1); i <= (N); i++) {
    ans += c[i];
    ans %= 1000000007ll;
  }
  cout << ans << endl;
}
