#include <bits/stdc++.h>
using namespace std;
namespace QoE_Library {
namespace QL_Bare_Minimum {
const double PI = 3.141592653589793238460;
const long double E = 2.7182818284590452353;
const long double pi = 10000 * acos(-1.0L);
template <typename T1>
void swap(T1 &x, T1 &y) {
  x = x + y;
  y = x - y;
  x = x - y;
}
void swapChars(char *a, char *b) {
  char tmp = *a;
  *a = *b;
  *b = tmp;
}
template <typename T1>
T1 gcd(T1 a, T1 b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
}  // namespace QL_Bare_Minimum
}  // namespace QoE_Library
using namespace QoE_Library::QL_Bare_Minimum;
int main() {
  int n;
  cin >> n;
  int nc = n;
  map<string, string> m1, m2;
  set<string> tr;
  while (nc--) {
    string str1, str2;
    cin >> str1 >> str2;
    int s0 = tr.size();
    int s1 = m1.size();
    int s2 = m2.size();
    if (s0 && tr.find(str2) != tr.end() || s1 && m1.find(str2) != m1.end() ||
        s2 && m2.find(str2) != m2.end()) {
      continue;
    } else if (s1 && m1.find(str1) != m1.end()) {
      string prevHandle = m1[str1];
      m1[str1] = str2;
      m2.erase(m2.find(prevHandle));
      m2.insert(make_pair(str2, str1));
      tr.insert(str1);
      tr.insert(str2);
    } else if (s2 && (m2.find(str1) != m2.end())) {
      string tmp = m2.find(str1)->second;
      m1.find(tmp)->second = str2;
      m2.erase(m2.find(str1));
      m2.insert(make_pair(str2, tmp));
      tr.insert(str1);
      tr.insert(str2);
    } else if ((!s2 || m2.find(str1) == m2.end()) &&
               (!s1 || m1.find(str1) == m1.end())) {
      if (!s2 || (m2.find(str1) == m2.end())) int deb = 0;
      if (!s1 || (m1.find(str1) == m1.end())) int deb = 0;
      m1.insert(make_pair(str1, str2));
      m2.insert(make_pair(str2, str1));
      tr.insert(str1);
      tr.insert(str2);
    }
  }
  cout << m1.size() << endl;
  for (map<string, string>::iterator it = m1.begin(); it != m1.end(); ++it) {
    cout << it->first << " " << it->second << endl;
  }
}
