#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n;
set<string> q;
map<string, string> p;
vector<string> ans;
string a, b;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    q.insert(b);
    if (!q.count(a)) ans.push_back(a);
    p[a] = b;
  }
  cout << ((int)(ans).size()) << endl;
  for (int i = 0; i < ((int)(ans).size()); i++) {
    string t = p[ans[i]];
    while (p.count(t)) t = p[t];
    cout << ans[i] << " " << t << endl;
  }
  return 0;
}
