#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct P {
  string s;
  int v;
};
bool operator<(P a, P b) {
  if (a.s == b.s) return a.v < b.v;
  return a.s < b.s;
}
int n;
P s;
map<P, vector<P>> g;
set<string> usd;
vector<P> q;
map<string, P> mp;
vector<P> ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    P u;
    cin >> u.s >> u.v;
    if (i == 0) s = u;
    int k;
    cin >> k;
    while (k--) {
      P v;
      cin >> v.s >> v.v;
      g[u].push_back(v);
    }
  }
  q.push_back(s);
  usd.insert(s.s);
  while (!q.empty()) {
    mp.clear();
    for (P u : q) {
      for (P v : g[u]) {
        if (usd.count(v.s)) continue;
        if (mp[v.s].v < v.v) mp[v.s] = v;
      }
    }
    q.clear();
    for (auto p : mp) {
      P u = p.second;
      q.push_back(u);
      usd.insert(u.s);
      ans.push_back(u);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (P p : ans) cout << p.s << " " << p.v << "\n";
  return 0;
}
