#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 3;
int n;
vector<pair<string, string> > v;
int search(const string &s) {
  if (v.size() == 0) return 0;
  for (int i = 0; i < v.size(); i++)
    if (v[i].second == s) return i + 1;
  return 0;
}
int main() {
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    if (search(a) == 0)
      v.push_back(make_pair(a, b));
    else {
      int k = search(a);
      v[k - 1].second = b;
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
  return 0;
}
