#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  vector<pair<string, string> > name;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, p;
    cin >> s >> p;
    int tmp = 0;
    for (int j = 0; j < name.size() && tmp == 0; j++)
      if (name[j].second == s) {
        name[j].second = p;
        tmp = 1;
      }
    if (tmp == 0) name.push_back(make_pair(s, p));
  }
  cout << name.size() << endl;
  for (int i = 0; i < name.size(); i++)
    cout << name[i].first << " " << name[i].second << endl;
  return 0;
}
