#include <bits/stdc++.h>
using namespace std;
int n;
int i;
char New[21], Old[21];
int main() {
  while (scanf("%d", &n) != EOF) {
    map<string, string> NewOld;
    for (i = 0; i < n; i++) {
      scanf("%s%s", New, Old);
      if (!NewOld.count(New)) {
        NewOld[New] = New;
      }
      NewOld[Old] = NewOld[New];
      NewOld.erase(New);
    }
    map<string, string>::iterator inter;
    cout << NewOld.size() << endl;
    for (inter = NewOld.begin(); inter != NewOld.end(); inter++)
      cout << inter->second << ' ' << inter->first << endl;
  }
  return 0;
}
