#include <bits/stdc++.h>
using namespace std;
map<string, string> old, nw;
map<string, int> mp;
int main() {
  int n, i, j, k;
  string a, b;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a >> b;
    if (!mp[a]) {
      mp[a] = 1;
      old[a] = a;
      if (!mp[b]) {
        mp[b] = 1;
        nw[a] = b;
        old[b] = a;
      }
    } else {
      if (!mp[b]) {
        mp[b] = 1;
        nw[old[a]] = b;
        old[b] = old[a];
      }
    }
  }
  int cnt = 0;
  for (__typeof(nw.begin()) it = nw.begin(); it != nw.end(); it++) {
    cnt++;
  }
  cout << cnt << endl;
  for (__typeof(nw.begin()) it = nw.begin(); it != nw.end(); it++) {
    cnt++;
    cout << (*it).first << " " << (*it).second << endl;
  }
}
