#include <bits/stdc++.h>
using namespace std;
map<string, string> M;
set<string> S;
struct node {
  string s1, s2;
} p[1005];
int main() {
  int n;
  while (cin >> n) {
    string s, e;
    M.clear();
    for (int i = 0; i < n; i++) {
      cin >> p[i].s1 >> p[i].s2;
      M[p[i].s1] = p[i].s2;
      S.insert(p[i].s1);
    }
    for (int i = 0; i < n; i++) {
      S.erase(p[i].s2);
    }
    set<string>::iterator it;
    int A = 0;
    for (it = S.begin(); it != S.end(); it++) {
      string str, ss;
      ss = str = *it;
      while (M[str] != "") str = M[str];
      p[A].s1 = ss;
      p[A++].s2 = str;
    }
    cout << A << endl;
    for (int i = 0; i < A; i++) cout << p[i].s1 << " " << p[i].s2 << endl;
  }
  return 0;
}
