#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
void solve() {
  int q;
  cin >> q;
  unordered_map<string, string> map;
  while (q--) {
    string a, b;
    cin >> a >> b;
    if (map.find(a) != map.end()) {
      string s = map[a];
      map.erase(a);
      map[b] = s;
      continue;
    }
    map[b] = a;
  }
  cout << map.size() << "\n";
  for (auto i : map) {
    cout << i.second << " " << i.first << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
