#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1234567;
const int MOD = 1e9 + 7;
vector<pair<string, string> > V;
vector<pair<string, string> > ans;
map<string, string> SP;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string old, neww;
    cin >> old >> neww;
    SP[old] = neww;
    V.push_back(pair<string, string>(old, neww));
  }
  set<string> used;
  for (int i = 0; i < V.size(); i++) {
    if (used.find(V[i].first) == used.end()) {
      string temp = V[i].second;
      used.insert(temp);
      while (SP.find(temp) != SP.end()) {
        used.insert(SP[temp]);
        temp = SP[temp];
      }
      ans.push_back(pair<string, string>(V[i].first, temp));
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
