#include <bits/stdc++.h>
using namespace std;
map<string, string> par, ans;
map<string, int> sz;
vector<pair<string, string> > v;
void make_set(string s) {
  par[s] = s;
  sz[s] = 1;
}
string Find(string s) { return (s == par[s]) ? s : par[s] = Find(par[s]); }
void Union(string x, string y) {
  string a = Find(x), b = Find(y);
  if (a == b) return;
  if (sz[a] >= sz[b]) {
    par[b] = a;
    sz[a] += sz[b];
  } else {
    par[a] = b;
    sz[b] += sz[a];
  }
}
int main() {
  string a, b;
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    make_set(a);
    make_set(b);
    v.push_back({a, b});
  }
  for (i = 0; i < n; i++) {
    Union(v[i].first, v[i].second);
  }
  for (i = 0; i < n; i++) {
    ans[Find(v[i].second)] = v[i].second;
  }
  cout << ans.size() << '\n';
  for (map<string, string>::iterator it = ans.begin(); it != ans.end(); it++) {
    cout << it->first << " " << it->second << '\n';
  }
}
