#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, j = 0;
  string c, d, s[1001];
  map<string, string> m;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c >> d;
    if (m[c] == "") {
      s[j++] = c;
      m[c] = d;
      m[d] = c;
    } else {
      m[m[c]] = d;
      m[d] = m[c];
      m.erase(c);
    }
  }
  cout << j << endl;
  for (i = 0; i < j; i++) {
    cout << s[i] << " " << m[s[i]] << endl;
  }
  return 0;
}
