#include <bits/stdc++.h>
using namespace std;
struct Person {
  string old, actual;
  Person(){};
  Person(string _old) { old = _old; };
};
int main() {
  string temp1, temp2;
  Person users[1002];
  int counter = 0, q;
  scanf("%d", &q);
  for (int x = 0; x < q; x++) {
    cin >> temp1 >> temp2;
    bool found = false;
    for (int y = 0; y < counter; y++) {
      if (users[y].actual == temp1) {
        users[y].actual = temp2;
        found = true;
      }
    }
    if (!found) {
      users[counter] = Person(temp1);
      users[counter++].actual = temp2;
    }
  }
  cout << counter << endl;
  for (int x = 0; x < counter; x++)
    cout << users[x].old << " " << users[x].actual << endl;
  return 0;
}
