#include <bits/stdc++.h>
using namespace std;
int mod = 10000007;
long long pwr(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long temp = pwr(a, b / 2, mod);
  temp = (temp * temp) % mod;
  if (b & 1) temp = (temp * a) % mod;
  return temp;
}
long long pwr(long long a, long long b) {
  if (b == 0) return 1;
  long long temp = pwr(a, b / 2);
  temp = (temp * temp);
  if (b & 1) temp = (temp * a);
  return temp;
}
bool *isPrime;
void generatePrimeSieve(const int lim) {
  isPrime = (bool *)malloc(lim + 1);
  memset(isPrime, true, lim + 1);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i <= lim; ++i)
    if (isPrime[i])
      for (int j = i + i; j <= lim; j += i) isPrime[j] = false;
}
vector<vector<int> > identityMatrix;
vector<vector<int> > mul(const vector<vector<int> > &a,
                         const vector<vector<int> > &b) {
  int n = a.size();
  vector<vector<int> > ans(n, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < n; ++k) {
        ans[i][j] += ((long long)a[i][k] * b[k][j]) % mod;
        ans[i][j] %= mod;
      }
    }
  }
  return ans;
}
vector<vector<int> > pwr(const vector<vector<int> > &a, long long n) {
  if (n == 0) {
    assert(false);
    return identityMatrix;
  }
  if (n == 1) return a;
  vector<vector<int> > tmp = pwr(a, n / 2);
  tmp = mul(tmp, tmp);
  if (n & 1) tmp = mul(a, tmp);
  return tmp;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long modularInverse(long long a, long long m) { return pwr(a, m - 2, m); }
int q;
struct node {
  string old, ne;
};
node arr[1002];
int main() {
  cin >> q;
  map<string, string> mp1, mp2;
  string str1, str2;
  for (int i = 0; i < q; ++i) {
    cin >> str1 >> str2;
    arr[i].old = str1;
    arr[i].ne = str2;
    for (int j = i - 1; j >= 0; --j) {
      if (arr[i].old == arr[j].ne) {
        arr[j].ne = arr[i].ne;
        arr[i].old = arr[j].old;
      }
    }
  }
  for (int i = 0; i < q; ++i) {
    mp1[arr[i].old] = arr[i].ne;
  }
  int sz = 0;
  for (std::map<string, string>::iterator it = mp1.begin(); it != mp1.end();
       ++it)
    sz++;
  cout << sz << endl;
  for (std::map<string, string>::iterator it = mp1.begin(); it != mp1.end();
       ++it)
    std::cout << it->first << " " << it->second << '\n';
}
