#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > g;
map<string, bool> visited;
vector<string> v;
map<string, bool> ex;
vector<pair<string, string> > res;
string out;
void dfs(string s) {
  visited[s] = 1;
  for (int i = 0; i < g[s].size(); i++) {
    string temp = g[s][i];
    if (!visited[temp]) out = temp, dfs(temp);
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a;
    if (!ex.count(a)) v.push_back(a), ex[a] = 1;
    cin >> b;
    if (!ex.count(b)) v.push_back(b), ex[b] = 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    if (!visited[v[i]]) {
      cnt++;
      dfs(v[i]);
      res.push_back(make_pair(v[i], out));
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < res.size(); i++)
    cout << res[i].first << " " << res[i].second << endl;
  return 0;
}
