#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int n;
string a[MAXN], b[MAXN];
vector<deque<string> > ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    bool k = false;
    for (int j = 0; j < ans.size(); j++) {
      deque<string> d = ans[j];
      if (d.front() == a[i]) {
        d.push_front(b[i]);
        k = true;
        ans[j] = d;
        break;
      }
    }
    if (!k) {
      deque<string> d;
      d.push_back(b[i]);
      d.push_back(a[i]);
      ans.push_back(d);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    deque<string> d = ans[i];
    cout << d.back() << " " << d.front() << endl;
  }
}
