#include<bits/stdc++.h>
using namespace std;
int n;
map<string,string>mp;  //第一个为关键字,第二个为键值 
int main(){
    cin >> n;
    for(int i=1;i<=n;++i){
        string str1,str2;
        cin >> str1 >> str2;
        if(mp.find(str1)==mp.end()){
            mp[str2]=str1;
        }
        else{
            mp[str2]=mp[str1];
            mp.erase(str1);
        }
    }
    cout << mp.size() << endl;
    map<string,string>::iterator it;
    for(it=mp.begin();it!=mp.end();++it){
        cout << it->second << " " << it->first << endl;  //输出键值和关键字
    }
    return 0;
}