#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int e = 1e7 + 79;
const int maxn = 1e6 + 69;
int t;
int main() {
  set<string> s;
  int dem = 0;
  cin >> t;
  map<string, string> mp;
  while (t--) {
    string Old, New;
    cin >> Old >> New;
    if (s.find(New) != s.end()) continue;
    s.erase(Old);
    s.insert(New);
    mp[New] = Old;
  }
  cout << s.size() << "\n";
  for (auto j : s) {
    string cur = j;
    while (mp[j] != "") {
      j = mp[j];
    }
    cout << j << " " << cur << "\n";
  }
}
