#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
int n;
pair<string, int> s;
map<string, int> ans;
map<pair<string, int>, vector<pair<string, int>>> g;
bool read() {
  if (!(cin >> n)) return false;
  for (int i = 0; i < int(n); ++i) {
    string name;
    int version;
    cin >> name >> version;
    if (i == 0) s = make_pair(name, version);
    int cnt;
    cin >> cnt;
    for (int _ = 0; _ < int(cnt); ++_) {
      string sname;
      int sversion;
      cin >> sname >> sversion;
      g[make_pair(name, version)].push_back(make_pair(sname, sversion));
    }
  }
  return true;
}
void bfs(pair<string, int> s) {
  vector<pair<string, int>> states;
  states.push_back(s);
  while (!states.empty()) {
    map<string, int> cur;
    for (auto it : states) {
      if (!ans.count(it.first)) {
        cur[it.first] = max(cur[it.first], it.second);
      }
    }
    states.clear();
    for (auto it : cur) {
      ans[it.first] = it.second;
      for (auto to : g[it]) states.push_back(to);
    }
  }
}
void solve() {
  bfs(s);
  ans.erase(s.first);
  cout << int((ans).size()) << endl;
  for (auto it : ans) cout << it.first << " " << it.second << endl;
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  while (read()) {
    solve();
  }
}
