#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  string s[n], s1, s2;
  vector<pair<string, string>> v;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    v.push_back({s1, s2});
  }
  vector<pair<string, string>> v1;
  for (int i = 0; i < v.size(); i++) {
    int f = 0;
    for (int j = i + 1; j < v.size(); j++) {
      if (v[i].second == v[j].first) {
        v[i].second = v[j].second;
        v.erase(v.begin() + j);
        f = 1;
      }
    }
    if (f == 1) i--;
  }
  cout << v.size() << "\n";
  for (auto i : v) cout << i.first << " " << i.second << "\n";
  return 0;
}
