#include <bits/stdc++.h>
using namespace std;
int n;
map<string, string> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) {
    string s, t;
    cin >> s >> t;
    if (mp[s] != "")
      mp[t] = mp[s];
    else
      mp[t] = s;
    mp.erase(s);
  }
  cout << mp.size() << '\n';
  for (auto it = mp.begin(); it != mp.end(); it++)
    cout << it->second << " " << it->first << '\n';
}
