#include <bits/stdc++.h>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
const long long MOD = 1e9 + 7;
const long long base = 269;
const int oo = 1 << 30;
const int N = 1e5 + 5;
long long P(long long x, long long y) {
  long long ret = 1;
  while (y > 0) {
    if (y & 1) ret *= x;
    y /= 2;
    x = x * x;
  }
  return ret;
}
long long GCD(long long a, long long b) { return (b ? GCD(b, a % b) : a); }
long long n, m, q, k, pos, rs = 1e18 + 1;
map<string, string> a;
map<string, string>::iterator it;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  string x, y;
  for (long long(i) = 0; (i) < (n); (i)++) {
    cin >> x >> y;
    if (a[x] == "") {
      a[y] = x;
      a.erase(x);
    } else {
      a[y] = a[x];
      a.erase(x);
    }
  }
  cout << a.size() << "\n";
  for (it = a.begin(); it != a.end(); it++) {
    cout << it->second << " " << it->first << "\n";
  }
}
