#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
;
int dx[] = {-1, 1, 0, 0, -1, 1, -1, 1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x / gcd(x, y)) * y; }
long long fastpow(long long a, long long b) {
  long long res = 1;
  int last;
  while (b) {
    if (b % 2) res *= a;
    b /= 2, a *= a;
  }
  return res;
}
bool isprime(long long n) {
  if (n == 1 || n == 0) return 0;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return 0;
  return 1;
}
int main() {
  fast();
  int q, coun = 0;
  cin >> q;
  map<string, string> mp;
  string New, old;
  while (q--) {
    cin >> old >> New;
    mp[old] = New;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    while (mp.find(it->second) != mp.end()) {
      string s = it->second;
      it->second = mp[s];
      mp[s] = "";
      coun++;
    }
  }
  cout << mp.size() - coun << "\n";
  for (auto it : mp)
    if (it.second != "") cout << it.first << " " << it.second << "\n";
}
