#include <bits/stdc++.h>
using namespace std;
int n, k, j;
string old[1005], New[1005], s1, s2;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s1 >> s2;
    for (j = 1; j <= k; ++j)
      if (New[j] == s1) {
        New[j] = s2;
        j = -1;
        break;
      }
    if (j != -1) old[++k] = s1, New[k] = s2;
  }
  cout << k << '\n';
  for (int i = 1; i <= k; ++i) cout << old[i] << " " << New[i] << '\n';
  return 0;
}
