#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max();
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
vector<pair<string, string> > a, b;
char used[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      string Old = a[i].first, New = a[i].second;
      for (int j = i + 1; j < n; j++) {
        if (a[j].first == New) {
          New = a[j].second;
          used[j] = 1;
        }
      }
      b.push_back(make_pair(Old, New));
    }
  }
  cout << (int)b.size() << "\n";
  for (int i = 0; i < (int)b.size(); i++)
    cout << b[i].first << " " << b[i].second << "\n";
  return 0;
}
