#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> a, b;
vector<string> c, d;
bool visited[1005];
void dfs(int i) {
  visited[i] = true;
  string now = b[i];
  int foundidx = -1;
  for (int j = 0; j < n; j++) {
    if (now == a[j]) {
      foundidx = j;
      break;
    }
  }
  if (foundidx == -1)
    d.push_back(now);
  else
    dfs(foundidx);
}
void first(int i) {
  if (visited[i] == false) {
    c.push_back(a[i]);
    dfs(i);
  }
}
int main(int argc, char* argv[]) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t1, t2;
    cin >> t1 >> t2;
    a.push_back(t1);
    b.push_back(t2);
  }
  for (int i = 0; i < 1005; i++) {
    visited[i] = false;
  }
  for (int i = 0; i < n; i++) {
    first(i);
  }
  cout << c.size() << endl;
  for (int i = 0; i < c.size(); i++) {
    cout << c[i] << " " << d[i] << endl;
  }
  return 0;
}
