#include <bits/stdc++.h>
const long long INF = 1000000000000;
using namespace std;
struct st {
  string s1, s2;
};
int main() {
  deque<st> v;
  st q;
  int i, j, n, c;
  string s, s1, s2;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    q.s1 = s;
    cin >> s;
    q.s2 = s;
    v.push_back(q);
  }
  c = 1;
  while (c != 0) {
    c = 0;
    for (i = 0; i < v.size(); i++) {
      for (j = i + 1; j < v.size(); j++) {
        if (v[i].s2 == v[j].s1) {
          v[i].s2 = v[j].s2;
          v.erase(v.begin() + j);
          j--;
          c++;
        }
      }
    }
  }
  cout << v.size() << endl;
  for (i = 0; i < v.size(); i++) {
    cout << v[i].s1 << " " << v[i].s2 << endl;
  }
  return 0;
}
