#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long INF = (long long)2e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 200005;
const long double pi = acosl(-1.0);
const long double eps = 1e-9;
char buff[15];
map<pair<string, int>, vector<pair<string, int>>> g;
void solve() {
  int n;
  scanf("%d", &n);
  pair<string, int> first;
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%s %d", buff, &v);
    string s(buff);
    if (i == 0) {
      first = make_pair(s, v);
    }
    vector<pair<string, int>> &cur = g[make_pair(s, v)];
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      scanf("%s %d", buff, &v);
      s = string(buff);
      cur.push_back(make_pair(s, v));
    }
  }
  map<string, int> ans;
  set<pair<string, int>> q;
  q.insert(first);
  while (!q.empty()) {
    vector<pair<string, int>> proj(q.begin(), q.end());
    reverse(proj.begin(), proj.end());
    q.clear();
    for (auto pr : proj) {
      if (ans.count(pr.first)) continue;
      ans[pr.first] = pr.second;
      vector<pair<string, int>> &child = g[pr];
      for (auto ch : child) q.insert(ch);
    }
  }
  printf("%d\n", (int)ans.size() - 1);
  for (auto pr : ans) {
    if (make_pair(pr.first, pr.second) == first) continue;
    printf("%s %d\n", pr.first.c_str(), pr.second);
  }
}
int main() {
  solve();
  return 0;
}
