#include <bits/stdc++.h>
using namespace std;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
const long double PI = 3.1415926535897932384626;
const long long int MAX = 1000000000 + 7;
int main() {
  map<string, string> mp;
  set<string> new1;
  long long int n;
  scanf("%lld", &n);
  string old, nw;
  for (long long int i = 0; i < n; i++) {
    cin >> old >> nw;
    mp[old] = nw;
    new1.insert(nw);
  }
  vector<pair<string, string> > vpp;
  for (__typeof((mp).begin()) it = (mp).begin(); it != (mp).end(); it++) {
    if (new1.count(it->first)) continue;
    string cur = it->second;
    while (mp.count(cur)) cur = mp[cur];
    vpp.push_back(make_pair(it->first, cur));
  }
  cout << vpp.size() << endl;
  for (__typeof((vpp).begin()) it = (vpp).begin(); it != (vpp).end(); it++) {
    cout << it->first;
    printf(" ");
    cout << it->second;
    printf("\n");
  }
  return 0;
}
