#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const signed long long int LINF = LLONG_MAX;
const double EPS = 1e-9;
const int MOD = 1000000007;
const int MAXN = 100001;
const int ALPH = 26;
const int DALPH = 52;
int q;
map<string, string> match, rmatch;
set<string> current;
int main() {
  scanf("%d", &q);
  while (q--) {
    string s1, s2;
    cin >> s1 >> s2;
    if (current.find(s1) == current.end()) {
      current.insert(s2);
      match[s1] = s2;
      rmatch[s2] = s1;
    } else {
      current.erase(s1);
      current.insert(s2);
      match[rmatch[s1]] = s2;
      rmatch[s2] = rmatch[s1];
      rmatch.erase(s1);
    }
  }
  printf("%d\n", (int)(match).size());
  for (pair<string, string> p : match) {
    cout << p.first << " " << p.second << '\n';
  }
}
