#include <bits/stdc++.h>
using namespace std;
string s[1005][2];
int main() {
  int m, si = 0;
  cin >> m;
  for (int i = 1, j; i <= m; ++i) {
    string a, b;
    cin >> a >> b;
    for (j = 0; j < si; ++j)
      if (a == s[j][1]) {
        s[j][1] = b;
        break;
      }
    if (j == si) {
      s[si][0] = a;
      s[si][1] = b;
      ++si;
    }
  }
  cout << si << endl;
  for (int i = 0; i < si; ++i) cout << s[i][0] << " " << s[i][1] << endl;
}
