#include <bits/stdc++.h>
using namespace std;
int i, j, k;
void A();
void B();
void C();
void D();
void E();
int main() {
  B();
  return 0;
}
void B() {
  int n;
  scanf("%d", &n);
  map<string, string> m, p;
  for (i = 0; i <= n - 1; i++) {
    string a, b;
    cin >> a >> b;
    if (p.find(a) != p.end()) {
      string s = p[a];
      m[s] = b;
      p.erase(a);
      p[b] = s;
    } else if (m.find(a) == m.end()) {
      m[a] = b;
      p[b] = a;
    }
  }
  printf("%d\n", m.size());
  map<string, string>::iterator it = m.begin();
  while (it != m.end()) {
    cout << it->first << " " << it->second << endl;
    it++;
  }
}
