#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double infd = 2e+9;
const int infi = (1 << 30) - 1;
const long long infl = (1ll << 60) - 1;
const int mod = 1e+9 + 7;
template <class T>
inline T sqr(T x) {
  return x * x;
}
int result = 0;
struct dsu {
  vector<int> parent, size, depth;
  dsu(int n) {
    parent.resize(n);
    for (int i = 0; i < n; i++) parent[i] = i;
    depth.resize(n);
    size.assign(n, 1);
  }
  int find_set(int v) {
    if (parent[v] == v) return v;
    int temp = find_set(parent[v]);
    depth[v] += depth[parent[v]];
    depth[v] %= mod;
    return parent[v] = temp;
  }
  void unit(int root, int x, int w) {
    size[root] += size[x];
    parent[x] = root;
    depth[x] += w;
    depth[x] %= mod;
  }
  void refresh() {
    for (int i = 0; i < (int)parent.size(); i++) {
      find_set(i);
    }
  }
};
int main() {
  int n;
  cin >> n;
  dsu d(n);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x, v;
      cin >> v >> x;
      v--;
      int v1 = d.find_set(v);
      x = (x + mod) % mod;
      int add = (d.depth[v] + x) % mod;
      d.unit(i, v1, add);
      result += add;
      result %= mod;
    }
  }
  cout << result;
  return 0;
}
