#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, res = 0;
  cin >> n;
  map<string, string> mp;
  while (n--) {
    string a, b;
    cin >> a >> b;
    if (mp[a] != "") {
      mp[b] = mp[a];
    } else {
      mp[b] = a;
    }
    mp.erase(a);
  }
  cout << mp.size() << endl;
  for (auto i : mp) cout << i.second << " " << i.first << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
