#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int i, n, j;
  cin >> n;
  int flag = 0;
  string str1, str2;
  string A[1010][5];
  int k = 0;
  for (i = 0; i < n; i++) {
    flag = 0;
    cin >> str1 >> str2;
    for (j = 0; j < k; j++) {
      if (A[j][1] == str1) {
        A[j][1] = str2;
        flag = 1;
      }
    }
    if (flag == 0) {
      A[k][0] = str1;
      A[k][1] = str2;
      k++;
    }
  }
  cout << k << endl;
  for (i = 0; i < k; i++) {
    cout << A[i][0] << " " << A[i][1] << endl;
  }
  return 0;
}
