#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i, p = 0, l, q = 0, r, t = 0;
  long long int k = 0, j = 0;
  map<long long int, string> m;
  map<long long int, string> a;
  map<long long int, string> b;
  cin >> l;
  vector<pair<long long int, string>> v;
  for (i = 0; i < l; i++) {
    string s, s1;
    cin >> s >> s1;
    m[i] = s;
    v.push_back(make_pair(i, s1));
  }
  for (i = 0; i < l; i++) {
    string s = v[i].second;
    if (m[i] == ".") continue;
    for (j = i + 1; j < l; j++) {
      if (m[j] != ".") {
        if (m[j] == s) {
          s = v[j].second;
          m[j] = '.';
        }
      }
    }
    a[k] = m[i];
    b[k] = s;
    k++;
  }
  cout << k << endl;
  for (i = 0; i < k; i++) cout << a[i] << " " << b[i] << endl;
}
