#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    if (i != v.size() - 1) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  return os;
}
void go() { cin.tie(nullptr)->sync_with_stdio(false); }
void solve() {
  int n;
  cin >> n;
  string x, y;
  vector<vector<string>> a, res;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    a.push_back({x, y});
  }
  vector<int> vis(1002);
  for (int i = 0; i < n; i++) {
    if (vis[i]) continue;
    x = a[i][0];
    y = a[i][1];
    for (int j = i + 1; j < n; j++) {
      if (vis[j]) continue;
      if (y == a[j][0]) {
        vis[j] = 1;
        y = a[j][1];
      }
    }
    res.push_back({x, y});
  }
  cout << res.size() << '\n';
  for (int i = 0; i < res.size(); i++) {
    cout << res[i][0] << ' ' << res[i][1] << '\n';
  }
}
int32_t main() {
  go();
  solve();
}
