#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, str_cnt = 0;
  cin >> n;
  vector<pair<string, string> > vps;
  map<string, int> m;
  for (int i = 0; i < n; ++i) {
    string str1, str2;
    cin >> str1 >> str2;
    if (!m[str1]) {
      vps.push_back({str1, str2});
      m[str1] = m[str2] = ++str_cnt;
    } else {
      m[str2] = m[str1];
      vps[m[str1] - 1].second = str2;
    }
  }
  cout << str_cnt << "\n";
  for (int i = 0; i < str_cnt; ++i)
    cout << vps[i].first << " " << vps[i].second << "\n";
  return 0;
}
