#include <bits/stdc++.h>
using namespace std;
struct node {
  string orig;
  string act;
} temp;
vector<node> str;
void check() {
  bool flag = 0;
  for (auto i = 0; i < str.size(); ++i) {
    if (temp.orig == str[i].act) {
      str[i].act = temp.act;
      flag = 1;
      break;
    }
  }
  if (!flag) {
    str.push_back(temp);
  }
}
bool cml(node x, node y) { return x.act < y.act; }
int main() {
  int n;
  cin >> n;
  string a, b;
  for (int i = 0; i < n; ++i) {
    cin >> temp.orig >> temp.act;
    check();
  }
  cout << str.size() << endl;
  for (auto i = 0; i < str.size(); ++i) {
    cout << str[i].orig << " " << str[i].act << endl;
  }
  return 0;
}
