#include <bits/stdc++.h>
using namespace std;
int q, cnt = 0;
string temp1, temp2;
int main() {
  scanf("%d", &q);
  pair<string, string> hand[1001];
  pair<string, string> ids[1001];
  for (int i = 0; i < q; i++) cin >> hand[i].first >> hand[i].second;
  for (int i = 0; i < q; i++) {
    int x = 0;
    bool flag = false;
    if (hand[i].second == hand[i].first) continue;
    for (int j = 0; j < q; j++) {
      if (hand[j].first == hand[j].second || i == j) continue;
      if (hand[i].second == hand[j].first) {
        flag = true;
        x++;
        hand[i].second = hand[j].second;
        temp1 = hand[i].first;
        temp2 = hand[i].second;
        hand[j].second = hand[j].first;
      }
    }
    if (x) {
      cnt++;
      ids[cnt].first = temp1;
      ids[cnt].second = temp2;
    }
    if (!flag) {
      ++cnt;
      ids[cnt].first = hand[i].first;
      ids[cnt].second = hand[i].second;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) {
    cout << ids[i].first << " " << ids[i].second << endl;
  }
  return 0;
}
