#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int minn = 1e5 + 9;
const int N = 5e3 + 123;
const int NN = 5e5 + 123;
const int PRI = 555557;
const int pri = 997;
int n;
map<string, bool> u;
map<string, string> p;
vector<string> q;
string get(string a) {
  if (p[a] == "\0") return a;
  return get(p[a]);
}
void unite(string a, string b) { p[a] = b; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string a, b;
    cin >> a >> b;
    if (!u[a]) {
      q.push_back(a);
    }
    unite(a, b);
    u[a] = 1;
    u[b] = 1;
  }
  cout << (int)(q.size()) << '\n';
  for (int i = 0; i < (int)(q.size()); i++) {
    cout << q[i] << ' ' << get(q[i]) << '\n';
  }
}
