#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
long long fastPow(long long x, long long b) {
  if (b == 0)
    return 1;
  else if (!(b & 1)) {
    return fastPow(x * x, b / 2);
  } else
    return x * fastPow(x * x, (b - 1) / 2);
}
struct def {
  string h = ">";
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  vector<pair<string, string>> v;
  vector<pair<string, string>> vv;
  map<string, def> m;
  map<string, bool> vis;
  while (q--) {
    string a, b;
    cin >> a >> b;
    def t;
    t.h = b;
    m[a] = t;
    v.push_back({a, b});
  }
  for (int i = 0; i < v.size(); i++) {
    if (!vis[v[i].first]) {
      string temp = v[i].first;
      vis[temp] = 1;
      string ans;
      while (temp != ">") {
        ans = temp;
        temp = m[temp].h;
        vis[temp] = 1;
      }
      vv.push_back({v[i].first, ans});
    }
  }
  cout << vv.size() << '\n';
  for (int i = 0; i < vv.size(); i++) {
    cout << vv[i].first << " " << vv[i].second << '\n';
  }
  return 0;
}
