#include <bits/stdc++.h>
using namespace std;
vector<string> top_sort;
map<string, bool> visited;
void dfs(string s, map<string, vector<string>> adj) {
  vector<string> childs = adj[s];
  visited[s] = 1;
  for (vector<string>::iterator i = childs.begin(); i != childs.end(); i++) {
    if (!visited[*i]) {
      dfs(*i, adj);
      top_sort.push_back(*i);
    }
  }
}
int main() {
  int n;
  cin >> n;
  map<string, vector<string>> adj;
  string old[n];
  for (int i = 0; i < n; i++) {
    string o, ne;
    cin >> o >> ne;
    adj[o].push_back(ne);
    old[i] = o;
  }
  int result = 0;
  map<string, string> output;
  for (int i = 0; i < n; i++) {
    dfs(old[i], adj);
    if (top_sort.size() != 0) {
      result += 1;
      output[old[i]] = top_sort[0];
      top_sort.clear();
    }
  }
  cout << result << endl;
  for (map<string, string>::iterator i = output.begin(); i != output.end();
       i++) {
    cout << i->first << " " << i->second << endl;
  }
}
