#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
inline T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
long long power(long long x, long long n) {
  long long result = 1;
  while (n) {
    if (n & 1) result = result * x % 1000000007;
    n = n / 2;
    x = x * x % 1000000007;
  }
  return result;
}
void solve() {
  int n;
  cin >> n;
  map<string, string> mapper;
  while (n--) {
    string old, nw;
    cin >> old >> nw;
    if (old == nw) return;
    if (mapper.find(old) != mapper.end()) {
      mapper[nw] = mapper.find(old)->second;
      mapper.erase(mapper.find(old));
    } else
      mapper[nw] = old;
  }
  cout << mapper.size() << endl;
  map<string, string>::iterator it = mapper.begin();
  while ((it) != mapper.end()) {
    cout << it->second << " " << it->first << endl;
    ++it;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
