#include <bits/stdc++.h>
using namespace std;
map<string, int> names_mapping;
map<int, string> numbers_mapping;
map<string, int> news;
vector<string> olds;
int p[10000];
int N, M;
string a, b;
int findSet(int x) { return x == p[x] ? x : p[x] = findSet(p[x]); }
void unite(int x, int y) {
  int fx = findSet(x);
  int fy = findSet(y);
  if (fx != fy) p[x] = y;
  return;
}
int main() {
  M = 0;
  cin >> N;
  news.clear();
  for (int i = 0; i < 10000; i++) {
    p[i] = i;
  }
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (news.find(a) != news.end()) {
      names_mapping[b] = M + 1;
      numbers_mapping[M + 1] = b;
      ++M;
    } else {
      olds.push_back(a);
      names_mapping[a] = M + 1;
      names_mapping[b] = M + 2;
      numbers_mapping[M + 1] = a;
      numbers_mapping[M + 2] = b;
      M += 2;
    }
    news[b] = 1;
    unite(names_mapping[a], names_mapping[b]);
  }
  cout << olds.size() << endl;
  for (int i = 0; i < olds.size(); i++) {
    cout << olds[i] << " " << numbers_mapping[findSet(names_mapping[olds[i]])]
         << endl;
  }
  return 0;
}
