#include <bits/stdc++.h>
using namespace std;
int visited[10000] = {0};
vector<int> adj[10000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  map<string, string> mp;
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    if (mp[a] == "") {
      mp.insert({b, a});
    } else {
      mp.insert({b, mp[a]});
    }
    mp.erase(a);
  }
  cout << mp.size() << endl;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    cout << it->second << " " << it->first << endl;
  }
  return 0;
}
