#include <bits/stdc++.h>
using namespace std;
long long fact(long long num) {
  long long x = 1;
  for (int i = 1; i <= num; ++i) {
    x = x * i;
  }
  return x;
}
void swap(long long *a, long long *b) {
  long long x = *b;
  *b = *a;
  *a = x;
}
int isPrime(long long num) {
  if (num <= 1) return 0;
  for (long long i = 2; i * i <= num; i++)
    if (num % i == 0) return 0;
  return 1;
}
long long cnt = 0;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, j, m = 0, x = 0, k, l, y, z = 0, sum = 0, ans = 0, total;
  long long minm = 100000005, maxm = 0;
  long long t;
  string s1, s2, s;
  long long q, p;
  cin >> n;
  std::map<string, string> mymap;
  map<string, string>::iterator itr;
  while (n--) {
    cin >> s1 >> s2;
    itr = mymap.find(s1);
    if (itr != mymap.end()) {
      mymap[s2] = itr->second;
      mymap.erase(itr);
    } else {
      mymap[s2] = s1;
    }
  }
  cout << mymap.size() << endl;
  for (itr = mymap.begin(); itr != mymap.end(); ++itr) {
    cout << itr->second << " " << itr->first << '\n';
  }
  return 0;
}
