#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> mp;
  for (int i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    if (mp.find(x) != mp.end()) {
      string temp = mp[x];
      mp.erase(x);
      mp[y] = temp;
    } else {
      mp[y] = x;
    }
  }
  cout << mp.size() << endl;
  for (auto i : mp) {
    cout << i.second << " " << i.first << endl;
  }
}
