#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  map<string, string> alias, real;
  while (t--) {
    string s, b;
    cin >> s >> b;
    if (real[s].size() > 0) {
      string tb = real[s];
      alias[tb] = b;
      real[b] = tb;
      continue;
    }
    alias[s] = b;
    real[b] = s;
  }
  map<string, string>::iterator it = alias.begin();
  vector<pair<string, string> > ab;
  cout << alias.size() << "\n";
  while (it != alias.end()) {
    cout << it->first << " " << it->second << "\n";
    it++;
  }
  return 0;
}
