#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
double pi = acos(-1);
int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1};
string a, b;
map<string, int> id;
map<int, string> revid;
set<string> name;
vector<string> beg;
vector<int> graph[5000];
bool vis[5000] = {};
string ans;
void dfs(int node) {
  for (int i = 0; i < graph[node].size(); i++) {
    int c = graph[node][i];
    if (!vis[c]) dfs(c);
  }
  if (graph[node].size() == 0) ans = revid[node];
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int j = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (name.count(a) == 0) {
      name.insert(a);
      id.insert({a, j});
      revid.insert({j++, a});
      beg.push_back(a);
    }
    if (name.count(b) == 0) {
      name.insert(b);
      id.insert({b, j});
      revid.insert({j++, b});
    }
    graph[id[a]].push_back(id[b]);
  }
  cout << beg.size() << "\n";
  for (int i = 0; i < beg.size(); i++) {
    dfs(id[beg[i]]);
    cout << beg[i] << " " << ans << "\n";
  }
  return 0;
}
