#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667177216")
const long long mod = 1000000007;
map<pair<string, int>, vector<pair<string, int>>> g;
map<string, int> used;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  queue<pair<string, int>> q;
  set<string> st;
  string t;
  for (int i = 0; i < n; i++) {
    pair<string, int> a;
    cin >> a.first >> a.second;
    st.insert(a.first);
    if (i == 0) {
      t = a.first;
      q.push(a);
    }
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      pair<string, int> b;
      cin >> b.first >> b.second;
      st.insert(b.first);
      g[a].push_back(b);
    }
    string buf;
    getline(cin, buf);
    getline(cin, buf);
  }
  for (auto(it) = (st).begin(); (it) != (st).end(); (it)++) {
    used[*it] = 0;
  }
  used[t] = 1;
  vector<pair<string, int>> ans;
  while (!q.empty()) {
    vector<pair<string, int>> tmp;
    for (; !q.empty();) {
      auto v = q.front();
      tmp.push_back(v);
      q.pop();
    }
    vector<pair<string, int>> check;
    for (int i = 0; i < tmp.size(); i++) {
      for (auto j : g[tmp[i]]) {
        check.push_back(j);
      }
    }
    sort((check).rbegin(), (check).rend());
    for (auto val : check) {
      if (used[val.first]) continue;
      q.push(val);
      used[val.first] = 1;
      ans.push_back(val);
    }
  }
  sort((ans).begin(), (ans).end());
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  }
  return 0;
}
