#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
using namespace std;
template <typename T>
T gcd(T a, T b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
typedef long double ld; typedef unsigned int uint; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1e-9; char TEMPORARY_CHAR;
typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(long long a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#else
#endif
ios_base::sync_with_stdio(false);
int q;
cin >> q;
map <string, string> edges;
set <string> nonBegin;
for (int i = 0; i < q; ++i) {
string OLD, NEW;
cin >> OLD >> NEW;
edges[OLD] = NEW;
nonBegin.insert(NEW);
}
vector <pair <string, string> > ans;
fori(p,edges) {
if (nonBegin.count(p->first)) {
continue;
}
string cur = p->first;
while (edges.count(cur)) {
cur = edges[cur];
}
ans.push_back(make_pair(p->first, cur));
}
cout << ans.size() << endl;
fori(p, ans) {
cout << p->first << " " << p->second << endl;
}
#ifdef LOCAL
cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // LOCAL
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGNscih4KSBtZW1zZXQoKHgpLCAwLCBzaXplb2YoeCkpCiNkZWZpbmUgYWxsKHgpICh4KS5iZWdpbigpLCAoeCkuZW5kKCkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBGb3IoaSwgc3QsIGVuKSBmb3IoaW50IGk9KHN0KTsgaTw9KGludCkoZW4pOyBpKyspCiNkZWZpbmUgRm9yZChpLCBzdCwgZW4pIGZvcihpbnQgaT0oc3QpOyBpPj0oaW50KShlbik7IGktLSkKI2RlZmluZSBmb3JuKGksIG4pIGZvcihpbnQgaT0wOyBpPChpbnQpKG4pOyBpKyspCiNkZWZpbmUgZm9yZChpLCBuKSBmb3IoaW50IGk9KG4pLTE7IGk+PTA7IGktLSkKI2RlZmluZSBmb3JpKGl0LCB4KSBmb3IgKF9fdHlwZW9mKCh4KS5iZWdpbigpKSBpdCA9ICh4KS5iZWdpbigpOyBpdCAhPSAoeCkuZW5kKCk7IGl0KyspCiNkZWZpbmUgaW4oeCkgaW50ICh4KTsgaW5wdXQoKHgpKTsKI2RlZmluZSB4IGZpcnN0CiNkZWZpbmUge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