#include <bits/stdc++.h>
using namespace std;
string s[1003][2];
int i, n, l;
int main() {
  cin >> n;
  l = n;
  for (i = 1; i <= n; i++) {
    string a, b;
    cin >> a >> b;
    s[i][0] = a;
    s[i][1] = b;
    for (int j = i - 1; j >= 1; j--)
      if (s[j][1] == a && s[j][0] != "") s[j][1] = b, s[i][0] = "", l--;
  }
  cout << l << '\n';
  for (i = 1; i <= n; i++)
    if (s[i][0] != "") cout << s[i][0] << ' ' << s[i][1] << '\n';
}
