#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct child {
  vector<pair<string, long long>> gr;
};
long long n, v, m;
pair<string, long long> started;
map<pair<string, long long>, child*> gt;
map<pair<string, long long>, long long> used;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string stroka;
    cin >> stroka >> v;
    child* nww = new child;
    if (i == 0) {
      started = {stroka, v};
    }
    gt[{stroka, v}] = nww;
    used[{stroka, v}] = 0;
    cin >> m;
    for (long long j = 0; j < m; j++) {
      cin >> stroka >> v;
      (nww->gr).push_back({stroka, v});
    }
  }
  queue<pair<string, long long>> que;
  queue<pair<string, long long>> PentiumPro;
  que.push(started);
  PentiumPro.push(started);
  set<string> answer;
  answer.insert(started.first);
  map<string, long long> vr;
  vr.insert(started);
  map<string, long long> c;
  c.insert({started.first, 0});
  set<pair<string, long long>> List;
  pair<string, long long> tec, tec1, tecp;
  child* t;
  while (!que.empty()) {
    tec = que.front();
    tecp = PentiumPro.front();
    t = gt[tec];
    que.pop();
    PentiumPro.pop();
    if (List.count(tec) == 1 || List.count(tecp) == 1 || used[tec]) {
      continue;
    }
    used[tec] = 1;
    for (long long i = 0; i < (t->gr).size(); i++) {
      tec1 = (t->gr)[i];
      if (answer.count(tec1.first) == 0) {
        que.push(tec1);
        PentiumPro.push(tec);
        vr.insert(tec1);
        c.insert({tec1.first, c[tec.first] + 1});
        answer.insert(tec1.first);
      } else {
        if (c[tec.first] + 1 == c[tec1.first] && tec1.second > vr[tec1.first]) {
          List.insert({tec1.first, vr[tec1.first]});
          vr[tec1.first] = tec1.second;
          que.push(tec1);
          PentiumPro.push(tec);
        }
      }
    }
  }
  vector<pair<string, long long>> coutt;
  for (auto& i : vr) {
    if (i.first != started.first) {
      coutt.push_back({i.first, i.second});
    }
  }
  sort((coutt).begin(), (coutt).end());
  cout << coutt.size() << "\n";
  for (long long i = 0; i < coutt.size(); i++) {
    cout << coutt[i].first << " " << coutt[i].second << "\n";
  }
  return 0;
}
