#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int main() {
  string user1[maxn], user2[maxn];
  string s1, s2;
  int q;
  cin >> q;
  int count = 0;
  while (q--) {
    cin >> s1 >> s2;
    int flag = 0;
    for (int i = 1; i <= count; i++) {
      if (s1 == user2[i]) {
        flag = i;
        break;
      }
    }
    if (!flag) {
      user1[++count] = s1;
      user2[count] = s2;
      continue;
    }
    user2[flag] = s2;
  }
  printf("%d\n", count);
  for (int i = 1; i <= count; i++) {
    cout << user1[i] << " " << user2[i] << endl;
  }
  return 0;
}
