#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
  int val;
  TreeNode* left;
  TreeNode* right;
  TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
struct ListNode {
  int val;
  ListNode* next;
  ListNode(int x) : val(x), next(NULL) {}
};
int nxt() {
  int x;
  cin >> x;
  return x;
}
long long nxtLong() {
  long long x;
  cin >> x;
  return x;
}
string nxtStr() {
  string x;
  cin >> x;
  return x;
}
char nxtChar() {
  char x;
  cin >> x;
  return x;
}
double nxtDouble() {
  double x;
  cin >> x;
  return x;
}
long double nxtLDouble() {
  long double x;
  cin >> x;
  return x;
}
TreeNode* makeTree(int n) {
  queue<TreeNode*> tree_nodes;
  TreeNode* root;
  if (n) {
    root = new TreeNode(nxt());
    tree_nodes.push(root);
  } else {
    return NULL;
  }
  while (!tree_nodes.empty()) {
    TreeNode* node = tree_nodes.front();
    tree_nodes.pop();
    bool left;
    cin >> left;
    if (left) {
      node->left = new TreeNode(nxt());
      tree_nodes.push(node->left);
    }
    bool right;
    cin >> right;
    if (right) {
      node->right = new TreeNode(nxt());
      tree_nodes.push(node->right);
    }
  }
  return root;
}
ListNode* makeLinkedList(int n) {
  ListNode* list = new ListNode(0);
  ListNode* dummy = list;
  for (int i = 0; i < n; ++i) {
    list->next = new ListNode(nxt());
    list = list->next;
  }
  return dummy->next;
}
const int mod = 1000000007;
void solve() {
  int n = nxt();
  vector<int> parent(n + 1), sum(n + 1);
  for (int i = 1; i <= n; ++i) {
    parent[i] = i;
  }
  function<int(int)> get_par = [&](int x) {
    if (parent[x] == x) {
      return x;
    }
    int y = get_par(parent[x]);
    sum[x] += sum[parent[x]];
    sum[x] %= mod;
    parent[x] = y;
    return y;
  };
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int k = nxt();
    for (int j = 0; j < k; ++j) {
      int v = nxt(), x = nxt();
      int u = get_par(v);
      parent[u] = i;
      sum[u] = x + sum[v];
      sum[u] %= mod;
      ans += sum[u];
      ans %= mod;
      if (ans <= 0) {
        ans += mod;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(9);
  solve();
  return 0;
}
