#include <bits/stdc++.h>
using namespace std;
struct Findname {
  string name;
  Findname *next;
};
int main() {
  int T;
  cin >> T;
  queue<Findname *> q, p;
  while (T--) {
    Findname *S, *s;
    int flag = 0;
    string t1, t2;
    cin >> t1 >> t2;
    while (!q.empty()) {
      s = q.front();
      q.pop();
      p.push(s);
      while (s && !flag) {
        if (t1 == s->name) {
          S = new Findname;
          S->next = NULL;
          S->name = t2;
          s->next = S;
          flag = 1;
          break;
        }
        s = s->next;
      }
    }
    q = p;
    while (!p.empty()) {
      p.front();
      p.pop();
    }
    if (!flag) {
      S = new Findname;
      S->name = t1;
      s = new Findname;
      s->name = t2;
      S->next = s;
      s->next = NULL;
      q.push(S);
    }
  }
  Findname *S;
  cout << q.size() << endl;
  while (!q.empty()) {
    S = q.front();
    q.pop();
    cout << S->name << " ";
    while (S->next) {
      S = S->next;
    }
    cout << S->name << endl;
  }
}
