#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 10;
const int MOD = (int)1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  map<string, string> revMap;
  int q;
  cin >> q;
  while (q--) {
    string old, neew;
    cin >> old >> neew;
    if (revMap.find(old) != revMap.end())
      revMap[neew] = revMap[old], revMap.erase(revMap.find(old));
    else
      revMap[neew] = old;
  }
  cout << revMap.size() << "\n";
  for (auto x : revMap) cout << x.second << " " << x.first << "\n";
  return 0;
}
