#include <bits/stdc++.h>
using namespace std;
long long fact(int n) {
  long long ret = 1;
  for (long long i = 2; i <= n; ++i) {
    ret *= i;
  }
  return ret;
}
long long gcd(long long a, long long b) {
  long long c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return b;
}
long long inv_mod(long long a, long long m) {
  long long c, temp;
  long long q0 = 0;
  long long q1 = 1;
  long long b = m;
  while (a != 0) {
    c = a;
    temp = q0 - (b / a) * q1;
    q0 = q1;
    q1 = temp;
    a = b % a;
    b = c;
  }
  return (q0 >= 0) ? q0 : m + q0;
}
long long mult_mod(long long n, long long k, long long m) {
  long long ans = (n * k) % m;
  return (ans >= 0) ? ans : m + ans;
}
long long add_mod(long long n, long long k, long long m) {
  long long ans = (n + k) % m;
  return (ans >= 0) ? ans : m + ans;
}
namespace std {
template <typename a, typename b>
struct hash<std::pair<a, b>> {
 private:
  const hash<a> ah;
  const hash<b> bh;

 public:
  hash() : ah(), bh() {}
  size_t operator()(const std::pair<a, b> &p) const {
    size_t seed = ah(p.first);
    return seed ^ (bh(p.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
  }
};
}  // namespace std
struct Node {
  string name;
  Node *next;
};
int main() {
  int q;
  cin >> q;
  map<string, pair<Node *, Node *>> heads;
  for (int i = 0; i < q; ++i) {
    string s, s2;
    cin >> s >> s2;
    Node *n2 = new Node();
    n2->name = s2;
    n2->next = nullptr;
    if (heads.count(s)) {
      heads[s2] = heads[s];
      heads.erase(s);
      heads[s2].second->next = n2;
      heads[s2].second = n2;
    } else {
      Node *n = new Node();
      n->name = s;
      n->next = n2;
      heads[s2].first = n;
      heads[s2].second = n2;
    }
  }
  cout << heads.size() << "\n";
  for (auto it : heads) {
    cout << it.second.first->name << " " << it.first << "\n";
  }
  return 0;
}
