#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int mod = 1000000000 + 7;
int n;
int m;
int root[100000];
int depth[100000];
pair<int, int> get(int x) {
  if (root[x] == x) return make_pair(x, 0);
  pair<int, int> tmp = get(root[x]);
  root[x] = tmp.first;
  depth[x] = (tmp.second + depth[x]) % mod;
  return make_pair(root[x], depth[x]);
}
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      int x, y;
      scanf("%d%d", &x, &y);
      x--;
      if (y < 0) y += mod;
      pair<int, int> tmp = get(x);
      root[tmp.first] = i;
      depth[tmp.first] = (tmp.second + y) % mod;
      ans = (ans + depth[tmp.first]) % mod;
    }
    root[i] = i;
    depth[i] = 0;
  }
  printf("%d\n", ans);
  return 0;
}
