#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string name[1005], old1[1005];
int main() {
  int n, j = 1;
  string old, nw;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> old >> nw;
    if (mp[old] == 0) {
      old1[j] = old;
      mp[old] = j;
      mp[nw] = j;
      name[j] = nw;
      j++;
    } else {
      mp[nw] = mp[old];
      name[mp[nw]] = nw;
    }
  }
  cout << j - 1 << endl;
  for (int i = 1; i <= j; i++) {
    cout << old1[i] << " " << name[i] << endl;
  }
}
