#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
const int MAXN = 519;
const int MAXM = 604000;
const long long INF = 1152921504;
const long long mod = 258280327;
map<string, string> mp;
map<string, string>::iterator it;
int main() {
  int n;
  mp.clear();
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    it = mp.find(a);
    if (it == mp.end())
      mp[b] = a;
    else {
      string s;
      s = it->second;
      mp.erase(it);
      mp[b] = s;
    }
  }
  cout << mp.size() << endl;
  for (it = mp.begin(); it != mp.end(); it++) {
    cout << it->second << " " << it->first << endl;
  }
}
