#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
template <class T>
T absolute(T a) {
  if (a > 0)
    return a;
  else
    return -a;
}
inline long long power(long long base, long long p) {
  long long ans = 1;
  while (p > 0) ans *= base, p -= 1;
  return ans;
}
int main() {
  vector<string> v;
  map<string, string> mp;
  int q;
  string a, b;
  map<string, bool> track;
  scanf("%d", &q);
  while (q--) {
    cin >> a >> b;
    if (track.find(a) == track.end()) v.push_back(a);
    mp[a] = b;
    track[a] = track[b] = true;
  }
  cout << v.size() << endl;
  for (int i = 0; i < (int)v.size(); i++) {
    cout << v[i] << ' ';
    a = v[i];
    while (mp.find(a) != mp.end()) {
      a = mp[a];
    }
    cout << a << endl;
  }
  return 0;
}
