#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
map<pair<string, int>, int> cnt;
vector<pair<string, int> > edge[maxn];
string name[maxn];
int version[maxn];
bool used[maxn];
map<string, int> ver;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> name[i] >> version[i];
    cnt[{name[i], version[i]}] = i;
    int k;
    cin >> k;
    edge[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> edge[i][j].first >> edge[i][j].second;
    }
  }
  vector<int> q[2];
  q[0].push_back(0);
  ver[name[0]] = version[0];
  bool g = 0;
  while (!q[g].empty()) {
    vector<int>().swap(q[!g]);
    vector<pair<string, int> > ps;
    for (auto v : q[g]) {
      for (auto p : edge[v]) {
        if (!used[cnt[p]]) {
          used[cnt[p]] = 1;
          ps.push_back(p);
        }
      }
    }
    sort(ps.begin(), ps.end(), [](pair<string, int> p, pair<string, int> q) {
      return p.second > q.second;
    });
    for (auto p : ps) {
      if (!ver.count(p.first)) {
        ver[p.first] = p.second;
        q[!g].push_back(cnt[p]);
      }
    }
    g = !g;
  }
  cout << ver.size() - 1 << "\n";
  for (auto p : ver) {
    if (p.first != name[0]) {
      cout << p.first << " " << p.second << "\n";
    }
  }
  return 0;
}
