#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using std::abs;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
void _dbg(const char* _s, T _h) {
  cerr << _s << " = " << _h << "\n";
}
template <typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
  int _b = 0;
  while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++;
  cerr << " = " << _h << ",";
  _dbg(_s + 1, _t...);
}
struct init {
  init() {
    cin.tie(0);
    std::iostream::sync_with_stdio(0);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);
    srand(300);
  }
  ~init() {}
} init;
const int MAXN = 2018;
map<pair<string, int>, vector<pair<string, int>>> dep;
map<string, int> t, love, kal;
int main() {
  int n;
  cin >> n;
  string poly;
  for (int i = 0; i < n; ++i) {
    string name;
    int v, k;
    cin >> name >> v >> k;
    if (!i) t[name] = love[poly = name] = v;
    for (int j = 0; j < k; ++j) {
      string boom;
      int meow;
      cin >> boom >> meow;
      dep[{name, v}].emplace_back(boom, meow);
    }
  }
  while (!love.empty()) {
    ;
    for (auto p : love) {
      ;
      for (auto w : dep[p]) {
        if (t.find(w.first) == t.end()) {
          if (kal.find(w.first) == kal.end() || kal[w.first] < w.second)
            kal[w.first] = w.second;
        }
      }
    }
    love = kal;
    for (auto p : kal) t.insert(p);
    kal.clear();
  }
  cout << t.size() - 1 << '\n';
  for (auto p : t)
    if (p.first != poly) cout << p.first << ' ' << p.second << '\n';
  return 0;
}
