#include <bits/stdc++.h>
using namespace std;
int n;
map<string, string> chain;
map<string, string> ans;
map<string, bool> used;
vector<string> uniqu;
string old, neew;
string check;
void FindChild(string s) {
  if (!chain[s].empty())
    FindChild(chain[s]);
  else {
    cout << " " << s << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> old >> neew;
    if (!used[old]) {
      uniqu.push_back(old);
      used[old] = true;
    }
    used[neew] = true;
    chain[old] = neew;
  }
  cout << uniqu.size() << endl;
  for (int i = 0; i < uniqu.size(); i++) cout << uniqu[i], FindChild(uniqu[i]);
}
