#include <bits/stdc++.h>
using namespace std;
string a[1005], b[1005];
vector<pair<string, string> > v;
map<string, int> vis;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[a[i]]) {
      vis[a[i]] = 1;
      vis[b[i]] = 1;
      string x = b[i];
      for (int j = i + 1; j < n; j++) {
        if (a[j] == x) {
          x = b[j];
          vis[x] = 1;
        }
      }
      cnt++;
      v.push_back({a[i], x});
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}
