//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h>

using namespace std;

#define         ll                         long  long
#define         lf                         double
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

ll a[110];
int main(){
    ll n,x,mx=-1,cnt=0;
    sfl(n),sfl(x);
    for(ll i=1;i<=n;i++){
        sfl(a[i]);
    }
    for(ll len=x;len<=100;len++){
        cnt=0;
        for(ll i=1;i<=n;i++){
            cnt += a[i]/len;
        }

        if(cnt*len>mx){
            mx=cnt*len;
        }
    }
    cout<<mx<<endl;
}


/*
ID:
PROG:
LANG: C++
 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <climits>
#include <cstdlib>
using namespace std;

const double Pi=acos(-1.0);

typedef long long ll;
typedef pair<int, int> pii;

#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

#define INF (1<<29)+123
#define LL_INF (1<<59)+123

int main ()
{
	if (fopen("data.in", "r"))
		Rd("data.in");

	int N, M, arr[100];

	scanf("%d", &N);
	scanf("%d", &M);
	for (int i = 0; i < N; i++)
		scanf("%d", &arr[i]);

	sort(arr, arr + N);
	int maxarea = 0;
	for (int i = 0, curr = 0; i < N; i++, curr = 0) {
		if (arr[i] < M) continue;
		for (int j = i; j < N; j++)
			curr += arr[j]/arr[i];

		maxarea = max(maxarea, curr*arr[i]);
	}

	printf("%d\n", maxarea);
	return 0;
}


/*
ID:
PROG:
LANG: C++
 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <climits>
#include <cstdlib>
using namespace std;

const double Pi=acos(-1.0);

typedef long long ll;
typedef pair<int, int> pii;

#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

#define INF (1<<29)+123
#define LL_INF (1<<59)+123

int main ()
{
	if (fopen("data.in", "r"))
		Rd("data.in");

	int N, M, arr[100];

	scanf("%d", &N);
	scanf("%d", &M);
	for (int i = 0; i < N; i++)
		scanf("%d", &arr[i]);

	sort(arr, arr + N);
	int maxarea = 0;
	for (int i = M, curr = 0; i <= 100; i++, curr = 0) {
		for (int j = 0; j < N; j++)
			curr += arr[j]/i;

		maxarea = max(maxarea, curr*i);
	}

	printf("%d\n", maxarea);
	return 0;
}


/*
ID:
PROG:
LANG: C++
 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <climits>
#include <cstdlib>
using namespace std;

const double Pi=acos(-1.0);

typedef long long ll;
typedef pair<int, int> pii;

#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

#define INF (1<<29)+123
#define LL_INF (1<<59)+123

int main ()
{
	if (fopen("data.in", "r"))
		Rd("data.in");

	int N, M, arr[100];

	scanf("%d", &N);
	scanf("%d", &M);
	for (int i = 0; i < N; i++)
		scanf("%d", &arr[i]);

	sort(arr, arr + N);
	int maxarea = 0;
	for (int i = M, curr = 0; i <= 100; i++, curr = 0) {
		if (arr[i] < M) continue;
		for (int j = 0; j < N; j++)
			curr += arr[j]/i;

		maxarea = max(maxarea, curr*i);
	}

	printf("%d\n", maxarea);
	return 0;
}


//lxrtxdy!
#include<bits/stdc++.h>
using namespace std;
int n,l,ans,mx,a[10005];
int main()
{
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=l;i<=100;i++)
    {
        ans=0;
        for(int j=1;j<=n;j++)
            ans+=a[j]/i;
        mx=max(mx,ans*i);
    }
    printf("%d",mx);
    return 0;
}
//stO lxr!


#include<bits/stdc++.h>
using namespace std;
int n,l,ans=0,mx=-1,a[10005];
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++){
    	cin>>a[i];
	}
    for(int i=l;i<=100;i++){
        ans=0;
        for(int j=1;j<=n;j++){
        	ans=ans+a[j]/i;
		}
        mx=max(mx,ans*i);
    }
    cout<<mx<<endl;
    return 0;
}


#include<iostream>
int main()
{
	long long a,b,a1[233333];
	std::cin>>a>>b;
	long long num=0;
	for(int i=1;i<=a;i++)
	{
	std::cin>>a1[i];
	num+=a1[i]/b;
	}
	std::cout<<num*b;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,d[101],e=0,f=0,h=0;
	cin>>a>>b;
	for(int c=0;c<a;c++)
	{
		cin>>d[c];
		e=max(e,d[c]);
	}
	for(int c=b;c<=e;c++)
	{
		for(int g=0;g<a;g++)
		{
			h+=d[g]/c;
		}
		f=max(f,h*c);
		h=0;
	}
	cout<<f;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l,ans1=0,a[10000],ans=0;
	cin>>n>>l;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int j=l;j<1000;j++)
	{
	ans=0;
    for(int i=0;i<n;i++)
	{
		ans+=a[i]/j;
	}
	ans1=max(ans1,ans*j);
    }
	cout<<ans1;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int n,l,a[10005];

int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int maxv=-1;
    for(int i=1;i<=100;i++)
    {
        int ans=0;
        for(int j=1;j<=n;j++)
            ans+=a[j]/i;
        maxv=max(maxv,ans*i);
    }
    cout<<maxv;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,l,ans=0,mx=-1,a[10005];
int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=l;i<=100;i++)
    {
        ans=0;
        for(int j=1;j<=n;j++)
            ans=ans+a[j]/i;
        mx=max(mx,ans*i);
    }
    cout<<mx;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l,a[101]={0},b=0,maxx=0;
	cin>>n>>l;
	for(int x=1;x<=n;x++)
	{
		cin>>a[x];
	}
	sort(a+1,a+n+1);
	for(int x=l;x<=a[n];x++)
	{
		b=0;
		for(int y=1;y<=n;y++)
		{
			if(a[y]>=l)
			{
				b+=a[y]/l;
			}
		}
		if(maxx<b*l)maxx=b*l;
	}
	cout<<maxx;
}


#include <bits/stdc++.h>
#define fint register int
using namespace std;
int f[1001];
int main()
{
	int n,m,maxn=0;
    cin>>n>>m;
    for(fint i=0;i<n;i++)
	{
		cin>>f[i];
		if(f[i]>maxn)
		maxn=f[i];
	}
	int ans=0;
    for(fint i=m;i<=maxn;i++)
    {
    	int sum=0;
    	for(fint j=0;j<n;++j)
    	sum+=f[j]/i;
    	sum*=i;
    	if(sum>ans)
    	ans=sum;
    }
	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
int a[100000],b[1000],d,sum[10000],l,c,r,p1,p2;
int n,m,k,i,x,y,t,j;
string s;
   int main()
{       cin>>n>>l;
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
          for(i=0;i<n;i++){
            if(a[i]>=l){
                t=a[i];
                break;
            }
        }
         for(i=0;i<n;i++){
          x+=a[i]/t;
        }
      cout<<x*l<<endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,m,ans=0,x;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		ans+=x/m;
	}
	if(ans>n)ans=n;
	printf("%d\n",ans*m);
}


#include<bits/stdc++.h>
using namespace std;
int n,l;
int a[10010],maxn,ans,maxsum;
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		maxn=max(maxn,a[i]);
	}
	if(l>maxn)
	{
		printf("0\n");
		return 0;
	}
	for(int i=l;i<=maxn;++i)
	{
		ans=0;
		for(int j=1;j<=n;++j)
		{
			ans+=a[j]/i;
		}
		maxsum=max(maxsum,ans*i);
	}
	printf("%d",maxsum);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,l,s=0,mx=-10001,a[100001];
int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=l;i<101;i++)
    {
        s=0;
        for(int j=1;j<=n;j++)s+=a[j]/i;
        mx=max(mx,s*i);
    }
    cout<<mx<<endl;
    return 0;
}


#include <cstdio>
int n,l,a[10005],maxn=-1;
int max(int a,int b){return a>b?a:b;}
int main()
{
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=l;i<=100;i++)
    {
        int ans=0;
        for(int j=1;j<=n;j++)
            ans+=a[j]/i;
        maxn=max(maxn,ans*i);
    }
    printf("%d",maxn);
}


#include<bits/stdc++.h>
using namespace std;
int n,l,a[10005];
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++)cin>>a[i];
    int maxv=-1;
    for(int i=l;i<=100;i++){
        int ans=0;
        for(int j=1;j<=n;j++)ans+=a[j]/i;
        if(maxv<ans*i)maxv=ans*i;
    }
    cout<<maxv;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,sum=0,L,n,a[110],tx=-1,tMax=0;
int main()
{
	cin>>n>>L;
	for(int i=1;i<=n;i++)
		cin>>a[i],tx=max(tx,a[i]);
	for(int i=L;i<=tx;i++)
		{
			sum=0;
			for(int j=1;j<=n;j++)
				sum+=a[j]/i;
			if(sum*i>tMax) tMax=sum*i;
		}
	cout<<tMax;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	int n,l;
	cin>>n>>l;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int maxs=0;
	for(int i=l;i<=100;i++)
	{
		int ans=0;
		for(int j=1;j<=n;j++)
		{
			ans+=a[j]/i;
		}
		maxs=max(maxs,ans*i);
	}
	cout<<maxs<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,l,a;
int ans=0;
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
	  {
	  	scanf("%d",&a);
	  	ans+=a/l;
	  }
	printf("%d",ans*l);
}


#include<bits/stdc++.h>
using namespace std;
int A[110];
int main(){
	int n,l,max1=0; cin>>n>>l;
	for(int i=1;i<=n;i++) cin>>A[i];
	for(int i=1;i<=n;i++){
		int a=A[i],b=0;
		for(int j=1;j<=n;j++){
			if(A[j]>=A[i]&&A[i]>=l){
				b+=A[j]/A[i];
			}
		}
		max1=max(max1,a*b);
	}
	cout<<max1<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;

map<string, string> all;

int main()
{
    ios::sync_with_stdio(false);
    int T; cin >> T;
    for(int i = 0; i < T; i++){
        string x, y; cin >> x >> y;
        if(all.count(x)){
            string t = all[x];
            all.erase(x);
            all[y] = t;
        }
        else
            all[y] = x;
    }
    for(auto i = all.begin(); i != all.end(); i++)
        cout << i->second << " " << i->first << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

map<string, string> all;

int main()
{
    ios::sync_with_stdio(false);
    int T; cin >> T;
    for(int i = 0; i < T; i++){
        string x, y; cin >> x >> y;
        if(all.count(x)){
            string t = all[x];
            all.erase(x);
            all[y] = t;
        }
        else
            all[y] = x;
    }
    cout << all.size() << endl;s
    for(auto i = all.begin(); i != all.end(); i++)
        cout << i->second << " " << i->first << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

map<string, string> all;
map<string, string>::iterator it;

int main()
{
    ios::sync_with_stdio(false);
    int T; cin >> T;
    for(int i = 0; i < T; i++){
        string x, y; cin >> x >> y;
        if(all.count(x)){
            string t = all[x];
            all.erase(x);
            all[y] = t;
        }
        else
            all[y] = x;
    }
    cout << all.size() << endl;
    for(it = all.begin(); it != all.end(); it++)
        cout << it->second << " " << it->first << endl;
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define x first
#define y second

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;

int main() {
  std::ios::sync_with_stdio(false);

  map<string, string> m;

  int q;

  cin >> q;

  for (int i = 0; i < q; i++) {
    string oldh, newh;
    cin >> oldh >> newh;

    if (m.find(oldh) == m.end()) {
      m[newh] = oldh;
    } else if (oldh != newh) {
      m[newh] = m[oldh];
      m.erase(oldh);
    }
  }

  for (auto it : m) {
    cout << it.second << " " << it.first << "\n";
  }

  return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define x first
#define y second

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;

int main() {
  std::ios::sync_with_stdio(false);

  map<string, string> m;

  int q;

  cin >> q;

  for (int i = 0; i < q; i++) {
    string oldh, newh;
    cin >> oldh >> newh;

    if (m.find(oldh) == m.end()) {
      m[newh] = oldh;
    } else {
      m[newh] = m[oldh];
      m.erase(oldh);
    }
  }

  for (auto it : m) {
    cout << it.second << " " << it.first << "\n";
  }

  return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define x first
#define y second

#define mp make_pair
#define pb push_back

typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;

int main() {
  std::ios::sync_with_stdio(false);

  map<string, string> m;

  int q;

  cin >> q;

  for (int i = 0; i < q; i++) {
    string oldh, newh;
    cin >> oldh >> newh;

    if (m.find(oldh) == m.end()) {
      m[newh] = oldh;
    } else {
      m[newh] = m[oldh];
      m.erase(oldh);
    }
  }

  cout << m.size() << "\n";
  for (auto it : m) {
    cout << it.second << " " << it.first << "\n";
  }

  return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <set>
#include <bitset>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
// #define forstl(i, s)    for(__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define WHITE 1
#define BLACK -1

vi dfs_num;
vector<vi> mat;
int w=0;
void dfs(int u){
    w = u;
    dfs_num[u] = BLACK;
    for(int i=0; i<mat[u].size(); i++){
        if(dfs_num[mat[u][i]] == WHITE)
            dfs(mat[u][i]);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in" , "r" , stdin);
    //freopen("out.out" , "w" , stdout);
#endif
    int q,c=0;
    cin >> q;
    mat.assign(2*q, vi(0));
    string u,v;
    map<string,int> mp;
    map<int, string> rmp;

    while(q--){
        cin >> u >> v;
        if(mp.count(u)==0) {
            mp[u] = c;
            rmp[c++] = u;
        }
        if(mp.count(v)==0) {
            mp[v] = c;
            rmp[c++] = v;
        }
        int a = mp[u];
        int b = mp[v];

        mat[a].push_back(b);
        mat[b].push_back(a);
    }

    dfs_num.assign(c,WHITE);
    int n=0;
    for (int i = 0; i < c; ++i){
        if(dfs_num[i]==WHITE){
            dfs(i);
            n++;
        }
    }
    cout << n<< endl;
    dfs_num.assign(c,WHITE);
    for (int i = 0; i < c; ++i){
         if(dfs_num[i]==WHITE){
            cout << rmp[i] << ' ';
            dfs(i);
            cout << rmp[w] << endl;
         }
    }

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <set>
#include <bitset>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
// #define forstl(i, s)    for(__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define WHITE 1
#define BLACK -1

vi dfs_num;
vector<vi> mat;
int w=0;
void dfs(int u){
    w = u;
    dfs_num[u] = BLACK;
    for(int i=0; i<mat[u].size(); i++){
        if(dfs_num[mat[u][i]] == WHITE)
            dfs(mat[u][i]);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in" , "r" , stdin);
    //freopen("out.out" , "w" , stdout);
#endif
    int q,c=0;
    cin >> q;
    mat.assign(2*q, vi(0));
    string u,v;
    map<string,int> mp;
    map<int, string> rmp;

    while(q--){
        cin >> u >> v;
        if(mp.count(u)==0) {
            mp[u] = c;
            rmp[c++] = u;
        }
        if(mp.count(v)==0) {
            mp[v] = c;
            rmp[c++] = v;
        }
        int a = mp[u];
        int b = mp[v];

        mat[a].push_back(b);
        mat[b].push_back(a);
    }

    dfs_num.assign(c,WHITE);
    for (int i = 0; i < c; ++i){
         if(dfs_num[i]==WHITE){
            cout << rmp[i] << ' ';
            dfs(i);
            cout << rmp[w] << endl;
         }
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *old[1011], *new[1011], a[30], b[30];

int main() {
	int i, n, OK, k = 0;
	for (i = 0; i < 1011; i++) {
		old[i] = (char*)malloc(25 * sizeof(char));
		new[i] = (char*)malloc(25 * sizeof(char));
	}
	scanf("%d", &n);
	while (n--) {
		scanf("%s %s", a, b);
		// check a
		OK = 0;
		for (i = 1; i <= k ; i++) {
			if (strcmp(a, new[i]) == 0) {
				strcpy(new[i], b);
				OK = 1;
			}
		}
		if (!OK) {
			k++; // start from 1
			strcpy(old[k], a);
			strcpy(new[k], b);
		}
	}
	printf("%d\n", k);
	for (i = 1; i <= k; i++) {
		printf("%s %s\n", old[i], new[i]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *old[1000], *new[1000], a[30], b[30];

int main() {
	int i, n, OK, k = 0;
	for (i = 0; i < 1000; i++) {
		old[i] = (char*)malloc(22 * sizeof(char));
		new[i] = (char*)malloc(22 * sizeof(char));
	}
	scanf("%d", &n);
	while (n--) {
		scanf("%s %s", a, b);
		// check a
		OK = 0;
		for (i = 1; i <= k ; i++) {
			if (strcmp(a, new[i]) == 0) {
				strcpy(new[i], b);
				OK = 1;
			}
		}
		if (!OK) {
			k++; // start from 1
			strcpy(old[k], a);
			strcpy(new[k], b);
		}
	}
	printf("%d\n", k);
	for (i = 1; i <= k; i++) {
		printf("%s %s\n", old[i], new[i]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *old[1002], *new[1002], a[30], b[30];

int main() {
	int i, n, OK, k = 0;
	for (i = 0; i < 1000; i++) {
		old[i] = (char*)malloc(22 * sizeof(char));
		new[i] = (char*)malloc(22 * sizeof(char));
	}
	scanf("%d", &n);
	while (n--) {
		scanf("%s %s", a, b);
		// check a
		OK = 0;
		for (i = 1; i <= k ; i++) {
			if (strcmp(a, new[i]) == 0) {
				strcpy(new[i], b);
				OK = 1;
			}
		}
		if (!OK) {
			k++; // start from 1
			strcpy(old[k], a);
			strcpy(new[k], b);
		}
	}
	printf("%d\n", k);
	for (i = 1; i <= k; i++) {
		printf("%s %s\n", old[i], new[i]);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n, m, t;
char old[1005][25], nxt[1005][25];
int check_o(char *x){
	int i = 0;
	for(; i < n; i++){
		if(strcmp(x, old[i]) == 0) return i;
	}
	return -1;
}
int check_n(char *x){
	int i = 0;
	for(; i < n; i++){
		if(strcmp(x, nxt[i]) == 0) return i;
	}
	return -1;
}
int main(int argc, char *argv[]){
	scanf("%d", &n);
	int i;
	for(i = 0; i < n; i++){
		char t1[25] = {}, t2[25] = {};
		scanf("%s%s", t1, t2);
		int res = check_o(t1);
		if(res == -1){
			res = check_n(t1);
			if(res == -1){
				sprintf(old[t], "%s", t1);
				sprintf(nxt[t++], "%s", t2);

			}else
				sprintf(nxt[res], "%s", t2);
		}else{
			sprintf(nxt[res], "%s", t2);
		}
	}
	for(i = 0; i < n; i++){
		if(nxt[i][0]) m++;
	}
	printf("%d\n", m);
	for(i = 0; i < n; i++){
		if(nxt[i][0]) printf("%s %s\n", old[i], nxt[i]);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Handle
{
    char _name [21];
    char _next_name [21];
};

int main()
{
    int q; fscanf(stdin, "%d", &q);

    struct Handle *array = (struct Handle*)malloc(sizeof(struct Handle)*q);
    int id = 0;

    int i;
    for(i = 0; i< q; i++)
    {
        char name [21] = "";
        char new_name [21] = "";
        fscanf(stdin, "%s %s", name, new_name);

        int j, found = 0;
        for(j = 0; j< id; j++)
        {
            if(strcmp(name, array[j]._next_name) == 0)
            {
                strcpy(array[j]._next_name, new_name);
                found = 1;
                break;
            }
        }

        if(!found)
        {
            strcpy(array[id]._name, name);
            strcpy(array[id]._next_name, new_name);
            id++;
        }
    }

    //Output
    fprintf(stdout, "%d", id);

    for(i = 0; i<id; i++)
    {
        fprintf(stdout, "\n%s %s", array[i]._name, array[i]._next_name);
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int q,i,j=0,t=0;
    char name[1000][100];
    char newname[1000][100];
    scanf("%d",&q);
    for(i=0; i<q; i++)
    {
        scanf("%s %s",&name[t],&newname[t]);
        t++;
        for(j=0; j<i; j++)
        {

            if(strcmp(newname[j],name[t-1])==0)
            {
                strcpy(newname[j],newname[t-1]);
                t--;

                break;
            }

        }

    }
    printf("%d\n",t);
    for(j=0; j<t; j++)
    {

        printf("%s %s\n",name[j],newname[j]);
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int q,i,j=0,t=0;
    char name[1000][20];
    char newname[1000][20];
    scanf("%d",&q);
    for(i=0; i<q; i++)
    {
        scanf("%s %s",&name[t],&newname[t]);
        t++;
        for(j=0; j<i; j++)
        {

            if(strcmp(newname[j],name[t-1])==0)
            {
                strcpy(newname[j],newname[t-1]);
                t--;

                break;
            }

        }

    }
    printf("%d\n",t);
    for(j=0; j<t; j++)
    {

        printf("%s %s\n",name[j],newname[j]);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int search(int arr[], int n, int x)
{
    int i;
    for (i=0; i<n; i++)
        if (arr[i] == x)
         return i;
    return -1;
}
int main()
{
    int i,q,j,k,n,z,y,flag;
    scanf("%d",&q);
    int s[q];
    char a[q+1][21],b[q+1][21],c,aans[q+1][21],bans[q+1][21];
    scanf("%c",&c);
    for(i=0;i<q;i++){
        scanf("%s",a[i]);
        scanf("%c",&c);
        gets(b[i]);
    }
    k=0;z=0;
    for(i=q-1;i>=0;i--){
        if(search(s,k,i)!=-1){
            continue;
        }
        for(j=i-1;j>=0;j--){
            if(search(s,k,j)!=-1){
                continue;
            }
            if(!strcmp(a[i],b[j])){
                strcpy(a[i],a[j]);
                a[i][strlen(a[j])]='\0';
                s[k]=j;
                k++;
            }
        }
        strcpy(aans[z],a[i]);
        aans[z][strlen(a[i])]='\0';
        strcpy(bans[z],b[i]);
        bans[z][strlen(b[i])]='\0';
        z++;
    }
    printf("%d\n",z);
    for(i=0;i<z;i++){
        printf("%s %s\n",aans[i],bans[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
char bu[25],buff[25],arr[1001][25],str[1001][25];
long i,j=0,k=0,l,m,n,t,x,y;
scanf("%ld",&n);
while(n--)
{
scanf("%s %s",bu,buff);
for(x=0;x<j;x++)
{
if((strcmp(bu,arr[x]))==0)
break;
}
if(x==j)
{
strcpy(str[k],bu);
strcpy(arr[j],buff);
k++;j++;
}
else
{
strcpy(arr[x],buff);
}
}
printf("%ld\n",k);
for(i=0;i<k;i++)
printf("%s %s\n",str[i],arr[i]);
return 0;
}


#include<stdio.h>
#include<string.h>
typedef struct tip
{
char eski[20],yeni[20];
}tip;
int main()
{
	tip str[1000];
	char str1[20][20];
	int i,j,q,e=0,f=0;
	scanf("%d",&q);
	for (i=0;i<q;i++)
	{
	scanf("%s %s",str1[0],str1[1]);
	for (j=0;j<i;j++)
		if (!strcmp(str[j].yeni,str1[0]))
		{
			strcpy(str[j].yeni,str1[1]);
			f=1;
		}
	if(!f)
	{
		strcpy(str[e].eski,str1[0]);
		strcpy(str[e++].yeni,str1[1]);
	}
	f=0;
	}
	printf("%d\n",e);
	for (i=0;i<e;i++)
		printf("%s %s\n",str[i].eski,str[i].yeni);
return 0;
}


#include<stdio.h>
#include<string.h>
typedef struct tip
{
char eski[30],yeni[30];
}tip;
int main()
{
	tip str[1000];
	char str1[30][30];
	int i,j,q,e=0,f=0;
	scanf("%d",&q);
	for (i=0;i<q;i++)
	{
	scanf("%s %s",str1[0],str1[1]);
	for (j=0;j<i;j++)
		if (!strcmp(str[j].yeni,str1[0]))
		{
			strcpy(str[j].yeni,str1[1]);
			f=1;
		}
	if(!f)
	{
		strcpy(str[e].eski,str1[0]);
		strcpy(str[e++].yeni,str1[1]);
	}
	f=0;
	}
	printf("%d\n",e);
	for (i=0;i<e;i++)
		printf("%s %s\n",str[i].eski,str[i].yeni);
return 0;
}


/* .................... compiled by alankar....................
*/

//......................SHORTCUTS..............................

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//...........................................................

#define pi 3.14159265358979323846  //float type
#define MAX 100000  //for rmq
#define SQRTMAX 317   //for rmq
//#define gc getchar_unlocked

#define FOR(i,a,b) for(i=(a);i<(b);i++)

//only for +ve and single terms
#define s(x) scanf("%d",&x);
#define sl(x) scanf("%llu",&x);
#define p(x) printf("%d\n",x);
#define pl(x) printf("%llu\n",x);
//..........................................................

typedef long long int ll;
const ll MOD=1000000007;

//returns int and +ve numbers

/*inline int inp(){
	int n=0;
	char c;
	c=gc();
	while(c<'0' || c>'9'){
		c=gc();
	}
	while(c>='0' && c<='9'){
		n=(n<<3)+(n<<1)+c-'0';
		c=gc();
	}
	return n;
}
*/
//...................................

//power with mod........long long int
 ll power(ll a,ll b,ll mod){
      if(b==0)
            return 1;
      ll temp=power(a,b/2,mod);
      temp=(temp*temp)%mod;
      if(b&1)
            temp=(temp*a)%mod;
      return temp;
}

 //power without mod........ int
int pwr(int a,int b){
      if(b==0)
            return 1;
      int temp=pwr(a,b/2);
      temp=(temp*temp);
      if(b&1)
            temp=(temp*a);
      return temp;
}
 // .....long long int
ll gcd(ll a,ll b){
      return b==0?a:gcd(b,a%b);
}
 //......long long int
ll lcm(ll a,ll b){
      return (a/gcd(a,b))*b;
}
 //......long long int with mod
ll modularInverse(ll a,ll m){
      return power(a,m-2,m);
}

 //only for int
// int min(int a,int b) { return a<b? a : b; }
 //int max(int a,int b) { return a>b? a : b; }

//normal compare func on integers //for qsort(name,size,sizeof(type),compare)
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
//.......................................................

//segment tree
//not template but how to use ST
//for minimum element
/*
long long s[400000];
long long a[1000000];
int create(long long b,long long e,long long n)
{
    if(b==e)
    {
        s[n]=a[b];
    }
    else
        {
            create(b,(b+e)/2,2*n+1);
            create((b+e)/2+1,e,2*n+2);
            s[n]=s[2*n+1]<s[2*n+2]?s[2*n+1]:s[2*n+2];
        }
    return 0;
}

//for finding minimum element b/w l and r
long long messi(long long b,long long e,long long l,long long r,long long n)
{
    long long i,j;
    if(e<l||b>r)
    {
        return 100000001;
    }
    if(b>=l&&e<=r)
    {
        return s[n];
    }
    i=messi(b,(b+e)/2,l,r,2*n+1);
    j=messi((b+e)/2+1,e,l,r,2*n+2);
    return i<j?i:j;
}
*/
//............................................................................
//range minimam query
//for mim and max number
/*

//preprocess create the min array

long min[SQRTMAX], max[SQRTMAX], b[MAX];
int size, n;

void preProcess(int n){
	int i=0, j=0, k=0;
	long minimum, maximum;

	size = sqrt(n);
	//printf("size = %d\n",size);
	while(j<size){
		minimum = maximum = b[i];
		for(k=0 ; k<size ; k++){
			if(minimum>b[i])
				minimum = b[i];
			if(maximum<b[i])
				maximum = b[i];
			i++;
		}
		min[j] = minimum;
		max[j] = maximum;
		j++;
	}
}

long findMin(int l, int r){
	int j, j2;
	long minimum = b[l];

	j = l/size + 1;
	j2 = r/size - 1;

	//printf("j= %d and j2 = %d\n", j,j2);
	while(l<j*size && l<=r){
		if(minimum > b[l]){
			minimum = b[l];

		}
		//printf("Checked for %d\n", l);
		l++;
	}
	while(j<=j2 && l<=r && j<size){
		if(minimum > min[j])
			minimum = min[j];
		l = (j+1)*size;
		//printf("Checked for %d  <-->  %d\n", j*size, l-1);
		j++;
	}
	while(l<=r){
		if(minimum > b[l]){
			minimum = b[l];
		}
		//printf("Checked for %d\n", l);
		l++;
	}
	return minimum;
}

//finding max value
long findMax(int l, int r){
	int j, j2;
	long maximum = b[l];

	j = l/size + 1;
	j2 = r/size - 1;

	//printf("j= %d and j2 = %d\n", j,j2);
	while(l<j*size && l<=r){
		if(maximum < b[l]){
			maximum = b[l];

		}
		//printf("Checked for %d\n", l);
		l++;
	}
	while(j<=j2 && l<=r && j<size){
		if(maximum < max[j])
			maximum = max[j];
		l = (j+1)*size;
		//printf("Checked for %d  <-->  %d\n", j*size, l-1);
		j++;
	}
	while(l<=r){
		if(maximum < b[l]){
			maximum = b[l];
		}
		//printf("Checked for %d\n", l);
		l++;
	}
	return maximum;
}
*/

//...........................................END OF TEMPLATE.................................................................
char a[1002][24],b[1002][24],ans[1002][24],ans1[1002][24];
int main()
{ int i,j,k,t,n,q,flag=0;
char ch;
s(q)
i=1;
while(q--)
{scanf("%c",&ch);
scanf("%s",&ans[i]);
scanf("%c",&ch);
scanf("%s",&ans1[i]);
flag=0;
FOR(k,1,i)
{
    if(!strcmp(b[k],ans[i]))
    {
       strcpy(b[k],ans1[i]) ;
       flag=1;
       break;
    }
}
if(flag==0)
{
    strcpy(a[i],ans[i]);
    strcpy(b[i],ans1[i]);
    i++;
}

}
p(i-1);
FOR(t,1,i)
{
    printf("%s %s\n",a[t],b[t]);
}

    return 0;
}


#include <stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LINE 20

bool char_arr_equal(char* arr1, char* arr2);

main() {

	//read first line, get q
	int q;
	scanf("%d", &q);

	char names[q][MAX_LINE];
	char oldnames[q][MAX_LINE];
	//initialize
	int i;
	for (i=0; i<q; i+=1){
		names[i][0] = '\0';
	}

	char oldname[MAX_LINE];
	char newname[MAX_LINE];
	int ii;
	int jj;
	int n_new = 0;
	for (ii=0; ii<q; ii+=1){
		scanf("%s %s", oldname, newname);

		//find old name
		for (jj=0; jj<q; jj+=1) {
			if (char_arr_equal(names[jj], oldname)) {
				strcpy(names[jj], newname);
				//printf("%s %d\n", names[jj], jj);
				break;
			}
			if (strlen(names[jj]) == 0) {
				strcpy(names[jj], newname);
				strcpy(oldnames[jj], oldname);
				n_new += 1;
				//printf("2nd %s %d\n", names[jj], jj);
				break;
			}
		}

	}

	printf("%d\n", n_new);
	for (ii=0; ii<q; ii+=1){
		if (strlen(names[ii]) == 0)
			break;
		printf("%s %s\n", oldnames[ii], names[ii]);
	}

}

bool char_arr_equal(char* arr1, char* arr2){

	return(strcmp(arr1, arr2) == 0);
}


#include <stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LINE 21

bool char_arr_equal(char* arr1, char* arr2);

main() {

	//read first line, get q
	int q;
	scanf("%d", &q);

	char names[q][MAX_LINE];
	char oldnames[q][MAX_LINE];
	//initialize
	int i;
	for (i=0; i<q; i+=1){
		names[i][0] = '\0';
	}

	char oldname[MAX_LINE];
	char newname[MAX_LINE];
	int ii;
	int jj;
	int n_new = 0;
	for (ii=0; ii<q; ii+=1){
		scanf("%s %s", oldname, newname);

		//find old name
		for (jj=0; jj<q; jj+=1) {
			if (char_arr_equal(names[jj], oldname)) {
				strcpy(names[jj], newname);
				//printf("%s %d\n", names[jj], jj);
				break;
			}
			if (strlen(names[jj]) == 0) {
				strcpy(names[jj], newname);
				strcpy(oldnames[jj], oldname);
				n_new += 1;
				//printf("2nd %s %d\n", names[jj], jj);
				break;
			}
		}

	}

	printf("%d\n", n_new);
	for (ii=0; ii<q; ii+=1){
		if (strlen(names[ii]) == 0)
			break;
		printf("%s %s\n", oldnames[ii], names[ii]);
	}

}

bool char_arr_equal(char* arr1, char* arr2){

	return(strcmp(arr1, arr2) == 0);
}


#include<stdio.h>
#include<string.h>
#define M 1000
int main(){
    char w[M][2][21],a[21],b[21];
    int n,i,size=0,found,j;
    scanf("%d",&n);
    if(n<1||n>1000)
        return -1;
    for(i=0; i<n; i++){
        scanf("%s%s",a,b);
        found=0;
        for(j=0; j<size&&!found; j++){
            if(strcmp(a,w[j][1])==0){
                strcpy(w[j][1],b);
                found=1;
            }
        }
        if(!found){
            strcpy(w[size][0],a);
            strcpy(w[size][1],b);
            size++;
        }

    }
    printf("%d\n",size);
    for(i=0; i<size; i++){
        printf("%s %s\n",w[i][0],w[i][1]);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>

char news[1000][20];
char olds[1000][20];
char new[20];
char old[20];

int main()
{
    int n, i, j, l = 0, flag = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %s", old, new);

        for(j = 0; j < l; j++){
            if(strcmp(news[j], old) == 0){
                strcpy(news[j], new);
                flag = 1;
                break;
            }
        }

        if(flag == 0){
            strcpy(news[l], new);
            strcpy(olds[l], old);
            l++;
        }

        flag = 0;
    }

    printf("%d\n", l);

    for(i = 0; i < l; i++) printf("%s %s\n", olds[i], news[i]);

    return 0;
}


#include<stdio.h>
#include<string.h>

char news[1000][30];
char olds[1000][30];
char new[30];
char old[30];

int main()
{
    int n, i, j, l = 0, flag = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %s", old, new);

        for(j = 0; j < l; j++){
            if(strcmp(news[j], old) == 0){
                strcpy(news[j], new);
                flag = 1;
                break;
            }
        }

        if(flag == 0){
            strcpy(news[l], new);
            strcpy(olds[l], old);
            l++;
        }

        flag = 0;
    }

    printf("%d\n", l);

    for(i = 0; i < l; i++) printf("%s %s\n", olds[i], news[i]);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct __handlenode {
    char word[21];
    struct __handlenode *left;
    struct __handlenode *right;
    struct __handlenode *parent;
    struct __handlenode *child;
    struct __handlenode *next;
    struct __handlenode *prev;
} Node;

Node *createNewNode(char *word) {
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->left = 0;
    newNode->right = 0;
    newNode->child = newNode;
    newNode->parent = newNode;
    newNode->prev = newNode;
    newNode->next = newNode;
    if (word != 0) {
        strcpy(newNode->word, word);
    }

    return newNode;
}

void insertList(Node *newNode, Node *prev, Node *next) {
    newNode->next = next;
    newNode->prev = prev;

    prev->next = newNode;
    next->prev = newNode;
}

Node* findNode(Node *root, char *word) {
    if (strcmp(root->word, word) < 0) {
        if (root->left == 0) {
            return 0;
        } else {
            return findNode(root->left, word);
        }
    } else if (strcmp(root->word, word) > 0) {
        if (root->right == 0) {
            return 0;
        } else {
            return findNode(root->right, word);
        }
    } else {
        return root;
    }
}

void insertTree(Node *root, Node *newNode) {
    if (strcmp(root->word, newNode->word) < 0) {
        if (root->left == 0) {
            root->left = newNode;
        } else {
            insertTree(root->left, newNode);
        }
    } else {
        if (root->right == 0) {
            root->right = newNode;
        } else {
            insertTree(root->right, newNode);
        }
    }
}

void removeNode(Node *remove) {
    remove->next->prev = remove->prev;
    remove->prev->next = remove->next;

    free(remove);
}

void destroy(Node *list) {
    Node *t1 = list->next;
    Node *t2 = 0;

    while (t1 != list) {
        t2 = t1->next;
        removeNode(t1);
        t1 = t2;
    }

    free(list);
}

int main(void) {
    int q = 0, cnt = 0;
    Node *root = 0, *list = createNewNode(0);
    Node *p = 0;
    Node *n1 = 0, *n2 = 0;
    char w1[21] = {0, }, w2[21] = {0, };

    scanf("%d", &q);
    while (q--) {
        scanf("%s %s", w1, w2);
        if (root == 0) {
            cnt++;
            root = createNewNode(w1);
            n1 = root;
            insertList(n1, list->prev, list);
            n2 = createNewNode(w2);
            insertTree(root, n2);
            n1->child = n2;
            n2->parent = n1;
        } else {
            n1 = findNode(root, w1);
            if (n1 == 0) {
                cnt++;
                n1 = createNewNode(w1);
                n2 = createNewNode(w2);
                insertList(n1, list->prev, list);
                insertList(n2, list->prev, list);
                insertTree(root, n1);
                insertTree(root, n2);
                n1->child = n2;
                n2->parent = n1;
            } else {
                strcpy(n1->word, w2);
            }
        }
    }

    printf("%d\n", cnt);

    p = list->next;
    while (p != list) {
        if (p->parent == p) {
            printf("%s %s\n", p->word, p->child->word);
        }
        p = p->next;
    }

    destroy(list);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct __handlenode {
    char word[21];
    struct __handlenode *left;
    struct __handlenode *right;
    struct __handlenode *parent;
    struct __handlenode *child;
    struct __handlenode *next;
    struct __handlenode *prev;
} Node;

Node *createNewNode(char *word) {
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->left = 0;
    newNode->right = 0;
    newNode->child = newNode;
    newNode->parent = newNode;
    newNode->prev = newNode;
    newNode->next = newNode;
    if (word != 0) {
        strcpy(newNode->word, word);
    }

    return newNode;
}

void insertList(Node *newNode, Node *prev, Node *next) {
    newNode->next = next;
    newNode->prev = prev;

    prev->next = newNode;
    next->prev = newNode;
}

Node* findNode(Node *root, char *word) {
    if (strcmp(root->word, word) < 0) {
        if (root->left == 0) {
            return 0;
        } else {
            return findNode(root->left, word);
        }
    } else if (strcmp(root->word, word) > 0) {
        if (root->right == 0) {
            return 0;
        } else {
            return findNode(root->right, word);
        }
    } else {
        return root;
    }
}

void insertTree(Node *root, Node *newNode) {
    if (strcmp(root->word, newNode->word) < 0) {
        if (root->left == 0) {
            root->left = newNode;
        } else {
            insertTree(root->left, newNode);
        }
    } else {
        if (root->right == 0) {
            root->right = newNode;
        } else {
            insertTree(root->right, newNode);
        }
    }
}

void removeNode(Node *remove) {
    remove->next->prev = remove->prev;
    remove->prev->next = remove->next;

    free(remove);
}

void destroy(Node *list) {
    Node *t1 = list->next;
    Node *t2 = 0;

    while (t1 != list) {
        t2 = t1->next;
        removeNode(t1);
        t1 = t2;
    }

    free(list);
}

int main(void) {
    int q = 0;
    Node *root = 0, *list = createNewNode(0);
    Node *p = 0;
    Node *n1 = 0, *n2 = 0;
    char w1[21] = {0, }, w2[21] = {0, };

    scanf("%d", &q);
    while (q--) {
        scanf("%s %s", w1, w2);
        if (root == 0) {
            root = createNewNode(w1);
            n1 = root;
            insertList(n1, list->prev, list);
            n2 = createNewNode(w2);
            insertTree(root, n2);
            n1->child = n2;
            n2->parent = n1;
        } else {
            n1 = findNode(root, w1);
            if (n1 == 0) {
                n1 = createNewNode(w1);
                n2 = createNewNode(w2);
                insertList(n1, list->prev, list);
                insertList(n2, list->prev, list);
                insertTree(root, n1);
                insertTree(root, n2);
                n1->child = n2;
                n2->parent = n1;
            } else {
                strcpy(n1->word, w2);
            }
        }
    }

    p = list->next;
    while (p != list) {
        if (p->parent == p) {
            printf("%s %s\n", p->word, p->child->word);
        }
        p = p->next;
    }

    destroy(list);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct __handlenode {
    char word[21];
    struct __handlenode *left;
    struct __handlenode *right;
    struct __handlenode *parent;
    struct __handlenode *child;
    struct __handlenode *next;
    struct __handlenode *prev;
} Node;

Node *createNewNode(char *word) {
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode->left = 0;
    newNode->right = 0;
    newNode->child = newNode;
    newNode->parent = newNode;
    newNode->prev = newNode;
    newNode->next = newNode;
    if (word != 0) {
        strcpy(newNode->word, word);
    }

    return newNode;
}

void insertList(Node *newNode, Node *prev, Node *next) {
    newNode->next = next;
    newNode->prev = prev;

    prev->next = newNode;
    next->prev = newNode;
}

Node* findNode(Node *root, char *word) {
    if (strcmp(root->word, word) < 0) {
        if (root->left == 0) {
            return 0;
        } else {
            return findNode(root->left, word);
        }
    } else if (strcmp(root->word, word) > 0) {
        if (root->right == 0) {
            return 0;
        } else {
            return findNode(root->right, word);
        }
    } else {
        return root;
    }
}

void insertTree(Node *root, Node *newNode) {
    if (strcmp(root->word, newNode->word) < 0) {
        if (root->left == 0) {
            root->left = newNode;
        } else {
            insertTree(root->left, newNode);
        }
    } else {
        if (root->right == 0) {
            root->right = newNode;
        } else {
            insertTree(root->right, newNode);
        }
    }
}

void removeNode(Node *remove) {
    remove->next->prev = remove->prev;
    remove->prev->next = remove->next;

    free(remove);
}

void destroy(Node *list) {
    Node *t1 = list->next;
    Node *t2 = 0;

    while (t1 != list) {
        t2 = t1->next;
        removeNode(t1);
        t1 = t2;
    }

    free(list);
}

Node *findChild(Node *n) {
    if (n->child == n) {
        return n;
    } else {
        return n->child = findChild(n->child);
    }
}

int main(void) {
    int q = 0, cnt = 0;
    Node *root = 0, *list = createNewNode(0);
    Node *p = 0;
    Node *n1 = 0, *n2 = 0;
    char w1[21] = {0, }, w2[21] = {0, };

    scanf("%d", &q);
    while (q--) {
        scanf("%s %s", w1, w2);
        if (root == 0) {
            root = createNewNode(w1);
            n1 = root;
            insertList(n1, list->prev, list);
            n2 = createNewNode(w2);
            insertTree(root, n2);
            n1->child = n2;
            n2->parent = n1;
        } else {
            n1 = findNode(root, w1);
            if (n1 == 0) {
                n1 = createNewNode(w1);
                n2 = createNewNode(w2);
                insertList(n1, list->prev, list);
                insertList(n2, list->prev, list);
                insertTree(root, n1);
                insertTree(root, n2);
                n1->child = n2;
                n2->parent = n1;
            } else {
                n2 = createNewNode(w2);
                n1 = findChild(n1);
                n1->child = n2;
                n2->parent = n1;

                insertTree(root, n2);
                insertList(n2, list->prev, list);
            }
        }
    }

    p = list->next;
    while (p != list) {
        if (p->parent == p) {
            cnt++;
        }
        p = p->next;
    }

    printf("%d\n", cnt);

    p = list->next;
    while (p != list) {
        if (p->parent == p) {
            printf("%s %s\n", p->word, findChild(p)->word);
        }
        p = p->next;
    }

    destroy(list);
    return 0;
}


#include "stdio.h"
#include "string.h"
struct person
{
        char old_name[20];
        char new_name[20];
}a[1000];
int main()
{
        int q,i,j,k,num;
        char name[20];
        while(scanf("%d",&q)==1){
                getchar();num=0;
                while(q--){
                        scanf("%s",name);
                        for(j=0;j<num;j++)
                                if(!strcmp(name,a[j].new_name)){
                                           scanf("%s",a[j].new_name);
                                           break;
                                }
                        if(j==num) {
                                 strcpy(a[num].old_name,name);
                                 scanf("%s",a[num++].new_name);
                        }
                }
                printf("%d\n",num);
                for(i=0;i<num;i++)
                                printf("%s %s\n",a[i].old_name,a[i].new_name);
        }
        return 0;
}


#include "stdio.h"
#include "string.h"
struct person
{
        char old_name[25];
        char new_name[25];
}a[1005];
int main()
{
        int q,i,j,k,num;
        char name[25];
        while(scanf("%d",&q)==1){
                getchar();num=0;
                while(q--){
                        scanf("%s",name);
                        for(j=0;j<num;j++)
                                if(!strcmp(name,a[j].new_name)){
                                           scanf("%s",a[j].new_name);
                                           break;
                                }
                        if(j==num) {
                                 strcpy(a[num].old_name,name);
                                 scanf("%s",a[num++].new_name);
                        }
                }
                printf("%d\n",num);
                for(i=0;i<num;i++)
                                printf("%s %s\n",a[i].old_name,a[i].new_name);
        }
        return 0;
}


#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define MAX 10001

typedef struct Node{
  char *oldest;
  char *newest;
  struct Node *next;
}node;

int is_equal(char *a, char *b){
  int i = 0;
  while(a[i] != '\0' && b != '\0'){
    if(a[i] != b[i])
      return -1;
    i++;
  }
  if(a[i] == '\0' && b[i] == '\0')
    return 0;
  else
    return -1;
}

int main(){
  int q = 0, i = 0;
  scanf("%d", &q);
  node *head = NULL;

  for(i = 0; i < q; i++){
    char *old = (char *)malloc(sizeof(char) *21);
    char *new = (char *)malloc(sizeof(char) *21);
    scanf("%s %s", old, new);
    /** if head is null then insert first pair directly inside the linked list **/
    if(head == NULL){
      printf("inserting head ...\n");
      head = (node *)malloc(sizeof(node));
      head->oldest = old;
      head->newest = new;
      head->next = NULL;
    }
    else{
      node *temp = head;
      // search for current old value in linked list
      int notFound = 1;
      while(temp != NULL && notFound == 1){
	char *current_handle = temp->newest;
	if(strcmp(current_handle, old) == 0){
	  printf("match found : %s \n", old);
	  notFound = 0;
	}
	else
	  temp = temp->next;
      }
      // if we found older handle
      if(notFound == 0){
	// replace newest in temp with new handle entered
	printf("we found a match.\n");
	temp->newest = new;
      }
      else if(temp == NULL){
	// go to last node
	temp = head;
	while(temp->next){
	  temp = temp->next;
	}
	// if did not find the handle then insert a new element at the end of list
	printf("could not find match... pair is : %s %s \n", old, new);
	node *new_node = (node *)malloc(sizeof(node));
	new_node->oldest = old;
	new_node->newest = new;
	new_node->next = NULL;
	// it will be next to current temp node
	temp->next = new_node;
      }
    }
  }
  // now print the final list
  node *temp = head;
  while(temp){
    printf("%s %s\n", temp->oldest, temp->newest);
    temp = temp->next;
  }
}


#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define MAX 10001

typedef struct Node{
  char *oldest;
  char *newest;
  struct Node *next;
}node;

int is_equal(char *a, char *b){
  int i = 0;
  while(a[i] != '\0' && b != '\0'){
    if(a[i] != b[i])
      return -1;
    i++;
  }
  if(a[i] == '\0' && b[i] == '\0')
    return 0;
  else
    return -1;
}

int main(){
  int q = 0, i = 0;
  scanf("%d", &q);
  node *head = NULL;

  for(i = 0; i < q; i++){
    char *old = (char *)malloc(sizeof(char) *21);
    char *new = (char *)malloc(sizeof(char) *21);
    scanf("%s %s", old, new);
    /** if head is null then insert first pair directly inside the linked list **/
    if(head == NULL){
      //printf("inserting head ...\n");
      head = (node *)malloc(sizeof(node));
      head->oldest = old;
      head->newest = new;
      head->next = NULL;
    }
    else{
      node *temp = head;
      // search for current old value in linked list
      int notFound = 1;
      while(temp != NULL && notFound == 1){
	char *current_handle = temp->newest;
	if(strcmp(current_handle, old) == 0){
	  //printf("match found : %s \n", old);
	  notFound = 0;
	}
	else
	  temp = temp->next;
      }
      // if we found older handle
      if(notFound == 0){
	// replace newest in temp with new handle entered
	//printf("we found a match.\n");
	temp->newest = new;
      }
      else if(temp == NULL){
	// go to last node
	temp = head;
	while(temp->next){
	  temp = temp->next;
	}
	// if did not find the handle then insert a new element at the end of list
	//printf("could not find match... pair is : %s %s \n", old, new);
	node *new_node = (node *)malloc(sizeof(node));
	new_node->oldest = old;
	new_node->newest = new;
	new_node->next = NULL;
	// it will be next to current temp node
	temp->next = new_node;
      }
    }
  }
  // now print the final list
  node *temp = head;
  while(temp){
    printf("%s %s\n", temp->oldest, temp->newest);
    temp = temp->next;
  }
  return 0;
}


#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define MAX 10001

typedef struct Node{
  char *oldest;
  char *newest;
  struct Node *next;
}node;

int is_equal(char *a, char *b){
  int i = 0;
  while(a[i] != '\0' && b != '\0'){
    if(a[i] != b[i])
      return -1;
    i++;
  }
  if(a[i] == '\0' && b[i] == '\0')
    return 0;
  else
    return -1;
}

int main(){
  int q = 0, i = 0;
  scanf("%d", &q);
  node *head = NULL;

  for(i = 0; i < q; i++){
    char *old = (char *)malloc(sizeof(char) *21);
    char *new = (char *)malloc(sizeof(char) *21);
    scanf("%s %s", old, new);
    /** if head is null then insert first pair directly inside the linked list **/
    if(head == NULL){
      printf("inserting head ...\n");
      head = (node *)malloc(sizeof(node));
      head->oldest = old;
      head->newest = new;
      head->next = NULL;
    }
    else{
      node *temp = head;
      // search for current old value in linked list
      int notFound = 1;
      while(temp != NULL && notFound == 1){
	char *current_handle = temp->newest;
	if(strcmp(current_handle, old) == 0){
	  //printf("match found : %s \n", old);
	  notFound = 0;
	}
	else
	  temp = temp->next;
      }
      // if we found older handle
      if(notFound == 0){
	// replace newest in temp with new handle entered
	//printf("we found a match.\n");
	temp->newest = new;
      }
      else if(temp == NULL){
	// go to last node
	temp = head;
	while(temp->next){
	  temp = temp->next;
	}
	// if did not find the handle then insert a new element at the end of list
	//printf("could not find match... pair is : %s %s \n", old, new);
	node *new_node = (node *)malloc(sizeof(node));
	new_node->oldest = old;
	new_node->newest = new;
	new_node->next = NULL;
	// it will be next to current temp node
	temp->next = new_node;
      }
    }
  }
  // now print the final list
  node *temp = head;
  while(temp){
    printf("%s %s\n", temp->oldest, temp->newest);
    temp = temp->next;
  }
  return 0;
}


#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define MAX 10001

typedef struct Node{
  char *oldest;
  char *newest;
  struct Node *next;
}node;

int is_equal(char *a, char *b){
  int i = 0;
  while(a[i] != '\0' && b != '\0'){
    if(a[i] != b[i])
      return -1;
    i++;
  }
  if(a[i] == '\0' && b[i] == '\0')
    return 0;
  else
    return -1;
}

int main(){
  int q = 0, i = 0;
  scanf("%d", &q);
  node *head = NULL;

  for(i = 0; i < q; i++){
    char *old = (char *)malloc(sizeof(char) *21);
    char *new = (char *)malloc(sizeof(char) *21);
    scanf("%s %s", old, new);
    /** if head is null then insert first pair directly inside the linked list **/
    if(head == NULL){
      //printf("inserting head ...\n");
      head = (node *)malloc(sizeof(node));
      head->oldest = old;
      head->newest = new;
      head->next = NULL;
    }
    else{
      node *temp = head;
      // search for current old value in linked list
      int notFound = 1;
      while(temp != NULL && notFound == 1){
	char *current_handle = temp->newest;
	if(strcmp(current_handle, old) == 0){
	  //printf("match found : %s \n", old);
	  notFound = 0;
	}
	else
	  temp = temp->next;
      }
      // if we found older handle
      if(notFound == 0){
	// replace newest in temp with new handle entered
	//printf("we found a match.\n");
	temp->newest = new;
      }
      else if(temp == NULL){
	// go to last node
	temp = head;
	while(temp->next){
	  temp = temp->next;
	}
	// if did not find the handle then insert a new element at the end of list
	//printf("could not find match... pair is : %s %s \n", old, new);
	node *new_node = (node *)malloc(sizeof(node));
	new_node->oldest = old;
	new_node->newest = new;
	new_node->next = NULL;
	// it will be next to current temp node
	temp->next = new_node;
      }
    }
  }
  // now print the final list
  node *temp = head;
  // first print the size of list i.e. number of users that changed their handles
  int size = 0;
  while(temp){
    temp = temp->next;
    size++;
  }
  printf("%d\n", size);
  temp = head;
  while(temp){
    printf("%s %s\n", temp->oldest, temp->newest);
    temp = temp->next;
  }
  return 0;
}


#include<stdio.h>
#include<string.h>
#define s(n) scanf("%d",&n)
#define p(n) printf("%d\n",n)
#define ss(s) scanf("%s",s)
#define ps(s) printf("%s",s)
#define max(a,b) ((a)<(b)?(b):(a))
#define fo(i,m,n) for(i=m;i<n;i++)
#define rep(i,n) fo(i,0,n)
typedef struct node
{
	char old[21];
	char new[21];
}pair;
int main()
{
	int i,j,n,f;s(n);pair a[n];
	for(i=0;n--;) {
		ss(a[i].old);f=1;
		fo(j,0,i) if(!strcmp(a[i].old,a[j].new)) { ss(a[j].new); f=0; break; } if(f==1) ss(a[i].new); i+=f;
	}
	while(--i>=0) printf("%s %s\n",a[i].old,a[i].new);
	return 0;
}


#include<stdio.h>
#include<string.h>
#define s(n) scanf("%d",&n)
#define p(n) printf("%d\n",n)
#define ss(s) scanf("%s",s)
#define ps(s) printf("%s",s)
#define max(a,b) ((a)<(b)?(b):(a))
#define fo(i,m,n) for(i=m;i<n;i++)
#define rep(i,n) fo(i,0,n)
typedef struct node
{
	char old[21];
	char new[21];
}pair;
int main()
{
	int i,j,n,f;s(n);pair a[n];
	for(i=0;n--;) {
		ss(a[i].old);f=1;
		fo(j,0,i) if(!strcmp(a[i].old,a[j].new)) { ss(a[j].new); f=0; break; } if(f==1) ss(a[i].new); i+=f;
	}
	p(i);while(--i>=0) printf("%s %s\n",a[i].old,a[i].new);
	return 0;
}


#include<stdio.h>
#include<string.h>
char s1[1005][105],s2[1005][105],flag[1005];
int main()
{
	int n,i,m,len,j,u,t;
	while(scanf("%d",&n)!=EOF)
	{
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		memset(flag,0,sizeof(flag));
		for(i=1;i<=n;i++){
			scanf("%s%s",s1[i],s2[i]);
			u=-1;
			for(j=1;j<i;j++){
				if(flag[j]==1)continue;
				if(strcmp(s1[i],s2[j])==0){
					u=j;break;
				}
			}
			if(u==-1){
				continue;
			}
			flag[i]=1;
			strcpy(s2[u],s2[i]);
		}
		t=0;
		for(i=1;i<=n;i++){
			if(flag[i]==0){
				t++;
			}
		}
		printf("%d\n",t);

		for(i=1;i<=n;i++){
			if(flag[i]==0){
				printf("%s %s\n",s1[i],s2[i]);
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main ()
{
	char old[1005][25],next[1005][25];
	char flag[1005]={0};
	int m,n;
	while (scanf("%d",&m)==1 && m!=0)
	{
		int i,j;
		int n;
		n=m;
		for(i=0;i<m;i++)
		{
			scanf("%s",old[i]);
			scanf("%s",next[i]);
			for(j=0;j<i;j++)
			{
				if(flag[j]==1)
					continue;
				if(strcmp(old[i],next[j])==0)
				{
					strcpy(next[j],next[i]);
					flag[i]=1;
					n--;
				}
			}
		}
		printf("%d\n",n);
		for(i=0;i<m;i++)
		{
			if(flag[i]==1)
			continue;
			else
			printf("%s %s\n",old[i],next[i]);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main ()
{
	char old[1005][25],next[1005][25];
	char flag[1005]={0};
	int m,n;
	while (scanf("%d",&m)==1 && m!=0)
	{
		int i,j;
		int n;
		n=m;
		for(i=0;i<m;i++)
		{
			scanf("%s",old[i]);
			scanf("%s",next[i]);
			for(j=0;j<i;j++)
			{
				if(flag[j]==1)
					continue;
				if(strcmp(old[i],next[j])==0)
				{
					strcpy(next[j],next[i]);
					flag[i]=1;
					n--;
					break;
				}
			}
		}
		printf("%d\n",n);
		for(i=0;i<m;i++)
		{
			if(flag[i]==1)
			continue;
			else
			printf("%s %s\n",old[i],next[i]);
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int n;
	char usr[1001][21],fin[1001][21];
	scanf("%d",&n);
	int i,j;
	for(i=0;i<n;i++)
	{
		scanf("%s %s",usr[i],fin[i]);
		for(j=0;j<i;j++)
		{
			if(strcmp(usr[i],fin[j])==0)
			{
				strcpy(fin[j],fin[i]);
				n--;
				i--;
				break;
			}
		}
	}
	printf("%d\n",n);
	for(i=0;i<n;i++)
		printf("%s %s\n",usr[i],fin[i]);
	return 0;
}


#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	scanf("%d", &n);
	char names_new[n][29];
	char names_org[n][29];
	int top = 0;
	int i;
	for (i = 0; i < n; ++i) {
		char old[29];
		char new[29];
		scanf("%s %s", old, new);
		int pos;//Position of old string, if present
		int j;
		int flag = 0;//1 when present previously
		for (j = 0; j < top; ++j) {
			if (strcmp(names_new[j], old) == 0) {
				flag = 1;
				pos = j;
				break;
			}
		}
		if (flag) {
			strcpy(names_new[pos], new);
		} else {
			strcpy(names_org[top], old);
			strcpy(names_new[top], new);
			top++;
		}
	}
	printf("%d\n", top);
	for (i = 0; i < top; ++i) {
		printf("%s %s\n", names_org[i], names_new[i]);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
    int i,j,n;
    scanf("%d",&n);
    char new[n+1][25],old[n+1][25];
    for( i=0;i<n;i++)
        scanf("%s %s",old[i],new[i]);
    for(i=n-1;i>=0;i--)
    {
        for(j=i-1;j>=0;j--)
        {
            if(!strcmp(old[i],new[j]))
            {
                strcpy(new[j],new[i]);
                strcpy(old[i],"NULL");
                break;
            }
        }
    }
    int cnt=0;
    for(i=0;i<n;i++)
    {
        if(strcmp(old[i],"NULL"))
            cnt++;
    }
    printf("%d\n",cnt);
    for(i=0;i<n;i++)
    {
        if(strcmp(old[i],"NULL"))
            printf("%s %s\n",old[i],new[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
struct name
{
	char old[21];
	char nw[21];
};
typedef struct name name;

int main()
{
	int n;
	scanf("%d", &n);
	int i;
	name nm[n];
	for(i=0; i<n; i++)
	{
		scanf("%s", nm[i].old);
		scanf("%s", nm[i].nw);
	}
	int data[n];
	for(i=0; i<n; i++)
		data[i] = 0;
	int temp1[n], temp2[n];
	int k = 0, l;
	int j;
	char str[21];

	for(i=0; i<n; i++)
	{
		if(data[i]==0)
		{
			temp1[k] = i;
			temp2[k] = i;
			int flag = 0;
			strcpy(str, nm[i].nw);
			for(j = i+1; j<n; j++)
			{
				if(!strcmp(str, nm[j].old) && (data[j] == 0))
				{
					strcpy(str, nm[j].nw);
					temp2[k] = j;
					data[j] = 1;
				}
			}
			k++;
		}
	}
	printf("%d\n", k);
	for(i=0; i<k; i++)
	{
		printf("%s %s\n", nm[temp1[i]].old, nm[temp2[i]].nw);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
char old_name[1010][25],new_name[1010][25];

main(){

    long i,j,k,n,check[1000],N=0,x;

    scanf("%ld",&n);
    for(i=0;i<n;i++) scanf("%s %s",old_name[i],new_name[i]);

    for(i=0;i<n;i++) check[i]=1;

    for(i=0;i<n;i++)
        if(check[i]==1)
           for(j=0;j<n;j++)
              if(j!=i&&check[j]==1){
                  x=strcmp(old_name[j],new_name[i]);
                  if(x==0){
                      check[i]=2;
                      check[j]=0;
                      strcpy(new_name[i],new_name[j]);
                      N++;
                  }
              }
    for(i=0;i<n;i++) if(check[i]==1) N++;

    printf("%ld\n",N);
    for(i=0;i<n;i++){
        if(check[i]==1||check[i]==2) printf("%s %s\n",old_name[i],new_name[i]);
    }

    return(0);
}


#include<stdio.h>
#include<string.h>
char old_name[1010][25],new_name[1010][25];

main(){

    long i,j,k,n,check[1000],N=0,x,c=1;

    scanf("%ld",&n);
    for(i=0;i<n;i++) scanf("%s %s",old_name[i],new_name[i]);

    for(i=0;i<n;i++) check[i]=1;

    while(c){
    c=0;
    for(i=0;i<n;i++)
       if(check[i]!=0)
         for(j=0;j<n;j++)
            if(j!=i&&check[j]!=0){
               x=strcmp(old_name[j],new_name[i]);
               if(x==0){
                  check[i]=2;
                  check[j]=0;
                  strcpy(new_name[i],new_name[j]);
                  c=1;
                  break;
               }
            }
    }
    for(i=0;i<n;i++) if(check[i]!=0) N++;

    printf("%ld\n",N);
    for(i=0;i<n;i++){
        if(check[i]!=0) printf("%s %s\n",old_name[i],new_name[i]);
    }
    return(0);
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    int list,i,count1=0,count2=0,j,flag;
    scanf("%d",&list);
    const char s[2] = " ";
    char state[1000];
    char *first,*second;
    char tab1[list][21],tab2[list][21];
    for(i=0;i<list;i++){
        scanf(" %[^\n]s",state);
        first = strtok(state, s);
        second = strtok(NULL, s);
        if(i==0){
            strcpy(tab1[count1++],first);
            strcpy(tab2[count2++],second);
        }
        else{
            flag=0;
            for(j=0;j<count2;j++){
                if( strcmp(first,tab2[j]) == 0 ){
                    strcpy(tab2[j],second);
                    flag=1;
                    break;
                }
            }

            if(flag!=1){
                strcpy(tab1[count1++],first);
                strcpy(tab2[count2++],second);
            }
        }
    }
    printf("%d\n",count2);
    for(i=0;i<count2;i++){
        printf("%s %s\n",tab1[i],tab2[i]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    int list,i,count1=0,count2=0,j,flag;
    scanf("%d",&list);
    const char s[2] = " ";
    char state[1000];
    char *first,*second;
    char tab1[list][21],tab2[list][21];
    for(i=0;i<list;i++){
        scanf(" %[^\n]s",state);
        first = strtok(state, s);
        second = strtok(NULL, s);
        if(i==0){
            strcpy(tab1[count1++],first);
            strcpy(tab2[count2++],second);
        }
        else{
            flag=0;
            for(j=0;j<count2;j++){
                if( strcmp(first,tab2[j]) == 0 ){
                    strcpy(tab2[j],second);
                    flag=1;
                    break;
                }
            }

            if(flag!=1){
                strcpy(tab1[count1++],first);
                strcpy(tab2[count2++],second);
            }
        }
    }
    for(i=0;i<count2;i++){
        printf("%s %s\n",tab1[i],tab2[i]);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main() {
	int i, j, q, n, found;
	static char s[21], t[21];
	static struct user {
		char old[21], new[21];
	} pp[1000];

	scanf("%d", &q);
	n = 0;
	for (i = 0; i < q; i++) {
		scanf("%s%s", s, t);
		found = 0;
		for (j = 0; j < n; j++)
			if (strcmp(pp[j].new, s) == 0) {
				memset(pp[j].new, 0, sizeof(pp[j].new));
				memcpy(pp[j].new, t, strlen(t));
				found = 1;
				break;
			}
		if (!found) {
			memcpy(pp[n].old, s, strlen(s));
			memcpy(pp[n].new, t, strlen(t));
			n++;
		}
	}
	printf("%d\n", n);
	for (i = 0; i < n; i++)
		printf("%s %s\n", pp[i].old, pp[i].new);
	return 0;
}


#include <stdio.h>
#include <string.h>

int main() {
	int i, q, n, found;
	static char s[21], t[21];
	static struct user {
		char old[21], new[21];
	} pp[1000];

	scanf("%d", &q);
	n = 0;
	while (q-- > 0) {
		scanf("%s%s", s, t);
		found = 0;
		for (i = 0; i < n; i++)
			if (strcmp(pp[i].new, s) == 0) {
				memset(pp[i].new, 0, sizeof(pp[i].new));
				memcpy(pp[i].new, t, strlen(t));
				found = 1;
				break;
			}
		if (!found) {
			memcpy(pp[n].old, s, strlen(s));
			memcpy(pp[n].new, t, strlen(t));
			n++;
		}
	}
	printf("%d\n", n);
	for (i = 0; i < n; i++)
		printf("%s %s\n", pp[i].old, pp[i].new);
	return 0;
}


#include <stdio.h>
#include <string.h>

int main() {
	int i, j, q, n, found;
	static struct user {
		char old[21], new[21];
	} pp[1000];
	static char s[21], t[21];

	scanf("%d", &q);
	n = 0;
	for (i = 0; i < q; i++) {
		scanf("%s%s", s, t);
		found = 0;
		for (j = 0; j < n; j++)
			if (strcmp(pp[j].new, s) == 0) {
				memset(pp[j].new, 0, sizeof(pp[j].new));
				memcpy(pp[j].new, t, strlen(t));
				found = 1;
				break;
			}
		if (!found) {
			memcpy(pp[n].old, s, strlen(s));
			memcpy(pp[n].new, t, strlen(t));
			n++;
		}
	}
	printf("%d\n", n);
	for (i = 0; i < n; i++)
		printf("%s %s\n", pp[i].old, pp[i].new);
	return 0;
}


#include <stdio.h>
#include <string.h>
int check(int a);
char a[1004][23],b[1004][23],temp1[23],temp2[23];
int main()
{
int n,i,j,c;
char temp;
scanf("%d",&n);
j=-1;
for(i=0;i<n;i++)
	{
	    scanf("%c",&temp);
            fflush(stdin);
            scanf("%s %s",temp1,temp2);
            c=check(j);
            //printf("%d\n",c);
	    if(c==-1)
		{
                    j++;
                    strcpy(b[j],temp2);
                    strcpy(a[j],temp1);
                }
	    else
                {
                    strcpy(b[c],temp2);
                }
	}
printf("%d\n",j+1);
for(i=0;i<=j;i++)
	{
            printf("%s %s\n",a[i],b[i]);
	}
return 0;
}
int check(int j)
{
int i;
for(i=0;i<=j;i++)
    {
       if(strcmp(temp1,b[i])==0)
       return i;
    }
return -1;
}


#include <stdio.h>
#include <string.h>
int check(int a);
char a[1004][23],b[1004][23],temp1[23],temp2[23];
int main()
{
int n,i,j,c;
char temp;
scanf("%d",&n);
j=-1;
for(i=0;i<n;i++)
    {
        //scanf("%c",&temp);
            fflush(stdin);
            scanf("%s %s",temp1,temp2);
            c=check(j);
            //printf("%d\n",c);
        if(c==-1)
        {
                    j++;
                    strcpy(b[j],temp2);
                    strcpy(a[j],temp1);
                }
        else
                {
                    strcpy(b[c],temp2);
                }
    }
printf("%d\n",j+1);
for(i=0;i<=j;i++)
    {
            printf("%s %s\n",a[i],b[i]);
    }
return 0;
}
int check(int j)
{
int i;
for(i=0;i<=j;i++)
    {
       if(strcmp(temp1,b[i])==0)
       return i;
    }
return -1;
}


#include <stdio.h>
#include <string.h>
int check(int a);
char a[1004][23],b[1004][23],temp1[23],temp2[23];
int main()
{
int n,i,j,c;
char temp;
scanf("%d",&n);
j=-1;
for(i=0;i<n;i++)
    {
        //scanf("%c",&temp);
            //fflush(stdin);
            scanf("%s %s",temp1,temp2);
            c=check(j);
            //printf("%d\n",c);
        if(c==-1)
        {
                    j++;
                    strcpy(b[j],temp2);
                    strcpy(a[j],temp1);
                }
        else
                {
                    strcpy(b[c],temp2);
                }
    }
printf("%d\n",j+1);
for(i=0;i<=j;i++)
    {
            printf("%s %s\n",a[i],b[i]);
    }
return 0;
}
int check(int j)
{
int i;
for(i=0;i<=j;i++)
    {
       if(strcmp(temp1,b[i])==0)
       return i;
    }
return -1;
}


#include <stdio.h>
#include <string.h>
int check(int a);
char a[1004][23],b[1004][23],temp1[23],temp2[23];
int main()
{
int n,i,j,c;
char temp;
scanf("%d",&n);
j=-1;
for(i=0;i<n;i++)
	{
	    scanf("%c",&temp);
            fflush(stdin);
            scanf("%s %s",temp1,temp2);
            c=check(j);
            //printf("%d\n",c);
	    if(c==-1)
		{
                    j++;
                    strcpy(b[j],temp2);
                    strcpy(a[j],temp1);
                }
	    else
                {
                    strcpy(b[c],temp2);
                }
	}
printf("%d\n",j+1);
for(i=0;i<=j;i++)
	{
            printf("%s %s\n",a[i],b[i]);
	}
}
int check(int j)
{
int i;
for(i=0;i<=j;i++)
    {
       if(strcmp(temp1,b[i])==0)
       return i;
    }
return -1;
}


#include<stdio.h>
#include<string.h>

typedef struct{
  char old[24];
  char new[24];
} list;

int main(void){
  char oldname[24],newname[24];
  int i,j,n,count=0,flg;
  list name[1000];

  scanf("%d%*c",&n);

  for(i=0;i<n;i++){
    scanf("%s%s*c",oldname,newname);
    flg=0;
    //printf("old:%s new:%s\n",oldname,newname);
    for(j=0;j<count;j++){
      if(strcmp(oldname,name[j].new)==0){
	strcpy(name[j].new,newname);
	flg=1;
	break;
      }else continue;
    }
    if(!flg){
      strcpy(name[count].old,oldname);
      strcpy(name[count].new,newname);
      count++;
    }
  }

  printf("%d\n",count);
  for(i=0;i<count;i++){
    printf("%s %s\n",name[i].old,name[i].new);
  }

  return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][50],char B[][50],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][50],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
    B[j][k]='\0';
}
int main()
{
    char A[1001][50];
    char B[1001][50];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    count++;
	}
    }
    printf("%d\n",count);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][1001],char B[][1001],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][1001],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
    B[j][k]='\0';
}
int main()
{
    char A[50][1001];
    char B[50][1001];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    count++;
	}
    }
    printf("%d\n",count);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][50],char B[][50],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][50],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
    B[j][k]='\0';
}
int main()
{
    char A[1001][50];
    char B[1001][50];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    count++;
	}
    }
    printf("%d\n",q-count+1);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][1001],char B[][1001],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][1001],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
}
int main()
{
    char A[50][1001];
    char B[50][1001];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    count++;
	}
    }
    printf("%d\n",count);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][1001],char B[][1001],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][1001],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
    B[j][k]='\0';
}
int main()
{
    char A[1001][50];
    char B[1001][50];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    count++;
	}
    }
    printf("%d\n",q-count+1);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int check(char A[][1001],char B[][1001],int i,int j)
{
    int a,b,flag=0,k;
    a=strlen(A[i]);
    b=strlen(B[j]);
    if(a==b)
    {
	for(k=0;k<a;k++)
	{
	    if(A[i][k]==B[j][k])
	    {
		flag=1;
	    }
	    else
	    {
		flag=0;
		break;
	    }
	}
	if(flag==1)
	{
	    return 1;
	}
	else
	{
	    return 0;
	}
    }
    else
    {
	return 0;
    }
}
void copy(char B[][1001],int i,int j)
{
    int a,k;
    a=strlen(B[i]);
    for(k=0;k<a;k++)
    {
	B[j][k]=B[i][k];
    }
    B[j][k]='\0';
}
int main()
{
    char A[50][1001];
    char B[50][1001];
    int flag[1001];
    int q,i,j,count=0;
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
	scanf("%s",A[i]);
	scanf("%s",B[i]);
	flag[i]=1;
    }
    for(i=0;i<q;i++)
    {
	for(j=(i+1);j<q;j++)
	{
	    if(check(B,A,i,j))
	    {
		count++;
	    }
	}
    }
    printf("%d\n",q-count);
    for(i=0;i<q;i++)
    {
	if(flag[i]==1)
	{
	    for(j=(i+1);j<q;j++)
	    {
		if(check(B,A,i,j))
		{
		    flag[j]=0;
		    copy(B,j,i);
		}
	    }
	    printf("%s %s\n",A[i],B[i]);
	}
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	k=n;
	char s[n][21];
	char s1[n][21];
	for(i=0;i<n;i++)
	{
		scanf("%s",s[i]);
		scanf("%s",s1[i]);
	}
//	if(strcmp(s[0],s[1])==0)
//		printf("YES");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i==j || strcmp("dont",s[j])==0)
				continue;
			//printf("YES");
			if(strcmp(s1[i],s[j])==0)
			{
			//	printf("YES\n");
				strcpy(s1[i],s1[j]);
				strcpy(s[j],"dont");
				k--;
			}
		}
	}
	printf("%d\n",k);
	for(i=0;i<n;i++)
	{if(strcmp(s[i],"dont")==0)
		continue;
		printf("%s ",s[i]);
		printf("%s\n",s1[i]);
	}

	return 0;
}


#include <string.h>
#include <stdio.h>
int main()
{
    char neww[21], old[21], A[2][1000][21];
    int n, i, j, k, sum, p, found;

    while (scanf("%d", &n)!=EOF)
    {
        p=0;
        for (i=0; i<n; i++)
        {
        found=0;

        scanf("%s%s", old, neww);

        for (j=0; j<p; j++)
        {
            if (strcmp(old, A[1][j])==0)
            {
                strcpy(A[1][j], neww);
                found++;
            }
        }
        if (found==0) {strcpy(A[0][p], old); strcpy(A[1][p], neww); p++;}

        }
        printf("%d\n", p);
        for (i=0; i<p; i++)
        {
            printf("%s %s\n", A[0][i], A[1][i]);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,n,m;
    scanf("%d",&n);
    char a[n][21],b[n][21];
    int flag[n];
    for(i=0;i<n;i++)
    {
        flag[i]=0;
        scanf("%s %s",a[i],b[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i!=j)
            {
                if(strcmp(b[i],a[j])==0)
                {
                    strcpy(b[i],b[j]);
                    flag[j]=1;
                    break;
                }
            }
        }
    }
    k=0;
    for(i=0;i<n;i++)
    if(flag[i]==0)
    k++;
    printf("%d\n",k);
    for(i=0;i<n;i++)
    if(flag[i]==0)
    printf("%s %s\n",a[i],b[i]);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,n,m;
    scanf("%d",&n);
    char a[n][21],b[n][21];
    int flag[n];
    for(i=0;i<n;i++)
    {
        flag[i]=0;
        scanf("%s %s",a[i],b[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i!=j)
            {
                if(strcmp(b[i],a[j])==0)
                {
                    strcpy(b[i],b[j]);
                    flag[j]=1;
                }
            }
        }
    }
    k=0;
    for(i=0;i<n;i++)
    if(flag[i]==0)
    k++;
    printf("%d\n",k);
    for(i=0;i<n;i++)
    if(flag[i]==0)
    printf("%s %s\n",a[i],b[i]);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
   int n;
   char old[1000][20],new[1000][20];
   scanf("%i",&n);
   int i=0,j=0,k;
   do{
      scanf("%s %s",old[i],new[i]);
      i++;
     }while(i<n);
   do{
      for (i=j+1; i<n; i++)
      {
       if (strcmp(new[j],old[i])==0)
       {
        strcpy(new[j],new[i]);
        for(k=i; k<n; k++)
        {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
       }
      }
      j++;
      }while(j<n);
    i=0;
    printf("%i\n",n);
    do{
       printf("%s %s\n",old[i],new[i]);
       i++;
       }while(i<n);
}


#include<stdio.h>
#include<string.h>
int main()
{
   int n;
   char old[1000][20],new[1000][20];
   scanf("%i",&n);
   int i=0;
   do{
      scanf("%s %s",old[i],new[i]);
      i++;
     }while(i<n);
   int j=0;
   do{
      for (i=j+1; i<n; i++)
      {
       if (strcmp(new[j],old[i])==0)
       {
        strcpy(new[j],new[i]);
        for(int k=i; k<n; k++)
        {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
       }
      }
      j++;
      }while(j<n);
    i=0;
    printf("%i\n",n);
    do{
       printf("%s %s\n",old[i],new[i]);
       i++;
       }while(i<n);
}


#include<stdio.h>
#include<string.h>
int main()
{
   int n;
   char old[1001][21],new[1001][21];
   scanf("%i",&n);
   int i=0,j=0,k;
   do{
      scanf("%s %s",old[i],new[i]);
      i++;
     }while(i<n);
   do{
      for (i=j+1; i<n; i++)
      {
       if (strcmp(new[j],old[i])==0)
       {
        strcpy(new[j],new[i]);
        for(k=i; k<(n-1); k++)
        {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
       }
      }
      j++;
      }while(j<(n-1));
    i=0;
    printf("%i\n",n);
    do{
       printf("%s %s\n",old[i],new[i]);
       i++;
       }while(i<n);
}


#include<stdio.h>
#include<string.h>
int main()
{
   int n;
   char old[1001][21],new[1001][21];
   scanf("%i",&n);
   int i=0,j=0,k;
   do{
      scanf("%s %s",old[i],new[i]);
      i++;
     }while(i<n);
   do{
      for (i=j+1; i<n; i++)
      {
       if (strcmp(new[j],old[i])==0)
       {
        strcpy(new[j],new[i]);
        for(k=i; k<n; k++)
        {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
       }
      }
      j++;
      }while(j<(n-1));
    i=0;
    printf("%i\n",n);
    do{
       printf("%s %s\n",old[i],new[i]);
       i++;
       }while(i<n);
}


#include<stdio.h>
#include<string.h>

int main() {
   int n;
   char old[1001][21],new[1001][21];
   scanf("%i",&n);
   int i=0,j=0,k;
   do {
      scanf("%s %s",old[i],new[i]);
      i++;
   } while(i<n);
   do {
      for (i=j+1; i<n; i++) {
       if (strcmp(new[j],old[i])==0) {
        strcpy(new[j],new[i]);
        for(k=i; k<(n-1); k++) {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
        i--;
       }
      }
      j++;
   } while(j<(n-1));
   i=0;
   printf("%i\n",n);
   do{
       printf("%s %s\n",old[i],new[i]);
       i++;
   } while(i<n);
   return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
   int n;
   char old[1000][20],new[1000][20];
   scanf("%i",&n);
   int i,j,k=0;
   do{
      scanf("%s %s",old[i],new[i]);
      i++;
     }while(i<n);
   do{
      for (i=j+1; i<n; i++)
      {
       if (strcmp(new[j],old[i])==0)
       {
        strcpy(new[j],new[i]);
        for(k=i; k<n; k++)
        {
         strcpy(old[k],old[k+1]);
         strcpy(new[k],new[k+1]);
        }
        n--;
       }
      }
      j++;
      }while(j<n);
    i=0;
    printf("%i\n",n);
    do{
       printf("%s %s\n",old[i],new[i]);
       i++;
       }while(i<n);
}


#include <stdio.h>
#include <string.h>

typedef struct
{
    char old[21];
    char new[21];
    int next;
} Request_t;
Request_t Q[1000];

int main()
{
    int N, i, j;
    scanf("%d", &N);
    for(i = 0; i < N; ++i)
    {
        scanf("%s %s", Q[i].old, Q[i].new);
        Q[i].next = -1;
    }
    for(i = 0; i < N - 1; ++i)
    {
        for(j = 0; j < N; ++j)
        {
            if(strcmp(Q[i].new , Q[j].old) == 0)
            {
                memcpy(Q[j].old, Q[i].old, strlen(Q[i].old));
                Q[j].old[strlen(Q[i].old)] = '\0';
                Q[i].next = j;
                break;
            }
        }
    }
    int Ans = 0;
    for(i = 0; i < N; ++i)
    {
        Ans += Q[i].next == -1;
    }
    printf("%d\n", Ans);
    for(i = 0; i < N; ++i)
    {
        if(Q[i].next == -1)
        {
            printf("%s %s\n", Q[i].old, Q[i].new);
        }
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
        int n,i,count=1,flag,j,k=0,l;
        scanf("%d",&n);
        char a[n][21],b[n][21],new[21],old[21],f[n];
        for(i=0;i<n;i++)
        {
                scanf("%s",a[i]);
                scanf("%s",b[i]);
                f[i]=1;
                if(i>0)
                {
                        for(j=0;j<i;j++)
                        {
                                if(strcmp(a[i],b[j])!=0)
                                        flag=1;
                                else
                                {
                                        flag=0;
                                        break;
                                }
                        }
                        if(flag==1)
                                count++;
                }
        }
        printf("%d\n",count);
        for(i=0;i<n;i++)
        {
                if(f[k]==1)
                {
                        strcpy(old,a[i]);
                        strcpy(new,b[i]);
                        if(i==n-1)
                                l=i;
                        else
                                l=i+1;
                        for(j=l;j<n;j++)
                        {
                                if(j==n-1)
                                        printf("%s %s\n",a[i],new);
                                else if(j<n-1)
                                {
                                        if(strcmp(new,a[j])==0)
                                        {
                                                strcpy(old,a[j]);
                                                strcpy(new,b[j]);
                                                f[j]=0;
                                        }

                                }
                        }
                }
                k++;
        }
        return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
        int n,i,count=1,flag,j,k=0,l;
        scanf("%d",&n);
        char a[n][21],b[n][21],new[21],old[21],f[n];
        for(i=0;i<n;i++)
        {
                scanf("%s",a[i]);
                scanf("%s",b[i]);
                f[i]=1;
                if(i>0)
                {
                        for(j=0;j<i;j++)
                        {
                                if(strcmp(a[i],b[j])!=0)
                                        flag=1;
                                else
                                {
                                        flag=0;
                                        break;
                                }
                        }
                        if(flag==1)
                                count++;
                }
        }
        printf("%d\n",count);
        for(i=0;i<n;i++)
        {
                if(f[k]==1)
                {
                        strcpy(old,a[i]);
                        strcpy(new,b[i]);
                        if(i==n-1)
                                l=i;
                        else
                                l=i+1;
                        for(j=l;j<n;j++)
                        {
                                if(strcmp(new,a[j])==0)
                                {
                                        strcpy(old,a[j]);
                                        strcpy(new,b[j]);
                                        f[j]=0;
                                }
                                if(j==n-1)
                                        printf("%s %s\n",a[i],new);
                        }
                }
                k++;
        }
        return 0;
}


//我想简化一下这个代码！
#include<stdio.h>
#include<string.h>
#define NUMBER 1000
#define NAME 20+1

char handle[2*NUMBER][NAME];
int n=0;
int used[2*NUMBER];
void print_database(){
	int i;
	for(i=0;i<n;i++){
		printf(" %s",handle[i]);
		if(used[i]) printf("*");
	}
	printf("\n");
}
int main() {
	int q;
	scanf("%d",&q);
	//整个数据库的大小是旧名字个数的两倍，就是每一个人都把旧名字换为新名字
	//这样出现的名字就有2倍个旧名字个数！
	int i,j;
	char old[NUMBER][NAME];
	char new[NUMBER][NAME];

	for(i=0;i<q;i++){
		scanf("%s%s",old[i],new[i]);
	}
	/*
	//首先所有旧的名字应该是已经被使用过的！
	//从题目中的例子看，不是这样！
	for(i=0;i<q;i++){
	strcpy(handle[i],old[i]);
	}
	n=q;
	*/
	int path[2*NUMBER];
	for(i=0;i<2*NUMBER;i++){
		path[i]=i;
	}
	int change[2*NUMBER];
	for(i=0;i<2*NUMBER;i++){
		change[i]=i;
	}

	//我们需要处理重复出现的旧名字吗？
	for(i=0;i<q;i++){
		//printf("第%d个处理要求\n",i);
		//如果申请不符合要求，是不是要拒绝申请？
		//就是不改变！
		int find=-1;
		//对于老名字，要么有，要么没有
		//没有就添加，有就直接使用！
		for(j=0;j<n;j++){
			if(strcmp(handle[j],old[i])==0){
				find=j;
				break;
			}
		}
		int old_i=0;
		if(find==-1){
			//添加一个记录
			strcpy(handle[n],old[i]);
			old_i=n;
			n++;
		}else{
			old_i=find;
		}
		find=-2;
		for(j=0;j<n;j++){
			if(strcmp(handle[j],new[i])==0){
				//正在使用中
				if(used[j]){
					find=-1;
				}else{
					//以前使用过，当下没有使用过！
					find=j;
				}
				break;
			}
		}
		int new_i=0;
		if(find==-2){
			//添加一个记录
			strcpy(handle[n],new[i]);
			new_i=n;
			n++;
		}else if(find==-1){
			//这个请求不能处理！
			continue;//直接处理下一个请求！
		}else{
			//以前使用过，当下没有使用过！
			new_i=find;
		}
		//path[old_i]=new_i;
		path[new_i]=old_i;
		used[new_i]=1;
		used[old_i]=0;
		//用反向的方法记录，为了能够递归查找！
		//printf("%s to %s\n",handle[old_i],handle[new_i]);
		//printf("old %d --> new %d\n",old_i,new_i);
		int root=new_i;
		while(path[root]!=root){
			//printf("root is %d\n",root);
			root=path[root];
		}
		/*printf("root is %d\n",root);
		printf("root is %s\n",handle[root]);
		print_database();
		printf("\n-------------\n");
		printf("%s to %s\n",handle[root],handle[new_i]);
		printf("root %d --> new %d\n",root,new_i);
		*/
		change[root]=new_i;
		//printf("\n-------------\n");
	}
	//printf("\n-----I-------\n");
	int count=0;
	for(i=0;i<2*NUMBER;i++){
		if(change[i]!=i){
			count++;
		}
	}

	printf("%d\n",count);
	for(i=0;i<2*NUMBER;i++){
		if(change[i]!=i){
			printf("%s %s\n",handle[i],handle[change[i]]);
		}
	}

	return 0;
}


#include<stdio.h>
#include<string.h>
#define NUMBER 1000
#define NAME 20+1

char handle[2*NUMBER][NAME];
int n=0;
int used[2*NUMBER];
void print_database(){
	int i;
	for(i=0;i<n;i++){
		printf(" %s",handle[i]);
		if(used[i]) printf("*");
	}
	printf("\n");
}
int main() {
	int q;
	scanf("%d",&q);
	//整个数据库的大小是旧名字个数的两倍，就是每一个人都把旧名字换为新名字
	//这样出现的名字就有2倍个旧名字个数！
	int i,j;
	char old[NUMBER][NAME];
	char new[NUMBER][NAME];

	for(i=0;i<q;i++){
		scanf("%s%s",old[i],new[i]);
	}
	/*
	//首先所有旧的名字应该是已经被使用过的！
	//从题目中的例子看，不是这样！
	for(i=0;i<q;i++){
	strcpy(handle[i],old[i]);
	}
	n=q;
	*/
	int path[2*NUMBER];
	for(i=0;i<2*NUMBER;i++){
		path[i]=i;
	}
	int change[2*NUMBER];
	for(i=0;i<2*NUMBER;i++){
		change[i]=i;
	}

	//我们需要处理重复出现的旧名字吗？
	for(i=0;i<q;i++){
		//printf("第%d个处理要求\n",i);
		//如果申请不符合要求，是不是要拒绝申请？
		//就是不改变！
		int find=-2;
		for(j=0;j<n;j++){
			if(strcmp(handle[j],old[i])==0){
				//正在使用中
				if(used[j]){
					find=j;
				}else{
					//以前使用过，当下没有使用过！
					find=j;
				}
				break;
			}
		}
		int old_i=0;
		if(find==-2){
			//添加一个记录
			strcpy(handle[n],old[i]);
			used[n]=0;//这个不会被使用！
			old_i=n;
			n++;

		}else if(find==-1){
			//这个请求不能处理！
			used[find]=0;//重新标记为将要使用的！
			old_i=find;
		}else{
			//以前使用过，当下没有使用过！
			used[find]=1;//重新标记为将要使用的！
			old_i=find;
		}
		find=-2;
		for(j=0;j<n;j++){
			if(strcmp(handle[j],new[i])==0){
				//正在使用中
				if(used[j]){
					find=-1;
				}else{
					//以前使用过，当下没有使用过！
					find=j;
				}
				break;
			}
		}
		int new_i=0;
		if(find==-2){
			//添加一个记录
			strcpy(handle[n],new[i]);
			used[n]=1;
			new_i=n;
			n++;
		}else if(find==-1){
			//这个请求不能处理！
			continue;//直接处理下一个请求！
		}else{
			//以前使用过，当下没有使用过！
			used[find]=1;//重新标记为将要使用的！
			new_i=find;
		}
		//path[old_i]=new_i;
		path[new_i]=old_i;
		used[new_i]=1;
		used[old_i]=0;
		//用反向的方法记录，为了能够递归查找！
		//printf("%s to %s\n",handle[old_i],handle[new_i]);
		//printf("old %d --> new %d\n",old_i,new_i);
		int root=new_i;
		while(path[root]!=root){
			//printf("root is %d\n",root);
			root=path[root];
		}
		/*printf("root is %d\n",root);
		printf("root is %s\n",handle[root]);
		print_database();
		printf("\n-------------\n");
		printf("%s to %s\n",handle[root],handle[new_i]);
		printf("root %d --> new %d\n",root,new_i);
		*/
		change[root]=new_i;
		//printf("\n-------------\n");
	}
	//printf("\n-----I-------\n");
	int count=0;
	for(i=0;i<2*NUMBER;i++){
		if(change[i]!=i){
			count++;
		}
	}

	printf("%d\n",count);
	for(i=0;i<2*NUMBER;i++){
		if(change[i]!=i){
			printf("%s %s\n",handle[i],handle[change[i]]);
		}
	}

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    int q,i,j,x=0;
    char **ne,**old;
    do
        scanf("%d",&q);
    while ((q<1)|| (q>1000));
    ne=(char **)malloc(q*sizeof(char *));
   old=(char  **)malloc(q*sizeof(char *));
   for (i=0;i<q;i++)
   {
       ne[i]=(char *)malloc(20);
       old[i]=(char *)malloc(20);
       scanf("%20s %20s",old[i],ne[i]);
   }
       for (i=0;i<q;i++)
       {
           for (j=(i+1);j<q;j++)
           {

               if (strcmp(ne[i],old[j])==0)
               {
                   x++;
                   strcpy(ne[i],ne[j]);
                   free(ne[j]);
                   free(old[j]);
               }
           }
       }

printf("%d\n",q-x);
for (i=0;i<x;i++)
    printf("%s %s\n",old[i],ne[i]);

return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    int q,i,j,x=0,k;
    char **ne,**old;
    do
        scanf("%d",&q);
    while ((q<1)|| (q>1000));
    ne=(char **)malloc(q*sizeof(char *));
   old=(char  **)malloc(q*sizeof(char *));
   for (i=0;i<q;i++)
   {
       ne[i]=(char *)malloc(20);
       old[i]=(char *)malloc(20);
       scanf("%20s %20s",old[i],ne[i]);
   }
       for (i=0;i<q;i++)
       {

           for (j=(i+1);j<q;j++)
           {

               if (strcmp(ne[i],old[j])==0)
               {

                   x++;
                   strcpy(ne[i],ne[j]);

                   for (k=j;k<(q-1);k++)
                   {
                       ne[k]=ne[k+1];
                       old[k]=old[k+1];
                   }
j--;
               }
           }
       }

printf("%d\n",q-x);
for (i=0;i<(q-x);i++)
    printf("%s %s \n",old[i],ne[i]);

return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    int q,i,j,x=0,k;
    char **ne,**old;
    do
        scanf("%d",&q);
    while ((q<1)|| (q>1000));
    ne=(char **)malloc(q*sizeof(char *));
   old=(char  **)malloc(q*sizeof(char *));
   for (i=0;i<q;i++)
   {
       ne[i]=(char *)malloc(20);
       old[i]=(char *)malloc(20);
       scanf("%20s %20s",old[i],ne[i]);
   }
       for (i=0;i<q;i++)
       {
           for (j=(i+1);j<q;j++)
           {

               if (strcmp(ne[i],old[j])==0)
               {
                   x++;
                   strcpy(ne[i],ne[j]);
                  /* free(ne[j]);
                   free(old[j]);*/
                   for (k=j;k<(q-1);k++)
                   {
                       ne[k]=ne[k+1];
                       old[k]=old[k+1];
                   }
               }
           }
       }

printf("%d\n",q-x);
for (i=0;i<(q-x);i++)
    printf("%s %s \n",old[i],ne[i]);

return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    int q,i,j,x=0,k;
    char **ne,**old;
    do
        scanf("%d",&q);
    while ((q<1)|| (q>1000));
    ne=(char **)malloc(q*sizeof(char *));
   old=(char  **)malloc(q*sizeof(char *));
   for (i=0;i<q;i++)
   {
       ne[i]=(char *)malloc(20);
       old[i]=(char *)malloc(20);
       scanf("%20s %20s",old[i],ne[i]);
   }
       for (i=0;i<q;i++)
       {

           for (j=(i+1);j<q;j++)
           {

               if (strcmp(ne[i],old[j])==0)
               {
                   j--;
                   x++;
                   strcpy(ne[i],ne[j]);

                   for (k=j;k<(q-1);k++)
                   {
                       ne[k]=ne[k+1];
                       old[k]=old[k+1];
                   }
               }
           }
       }

printf("%d\n",q-x);
for (i=0;i<(q-x);i++)
    printf("%s %s \n",old[i],ne[i]);

return 0;

}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main ()
{
    int q,i,j,x=0,k;
    char **ne,**old;
    do
        scanf("%d",&q);
    while ((q<1)|| (q>1000));
    ne=(char **)malloc(q*sizeof(char *));
   old=(char  **)malloc(q*sizeof(char *));
   for (i=0;i<q;i++)
   {
       ne[i]=(char *)malloc(20);
       old[i]=(char *)malloc(20);
       scanf("%20s %20s",old[i],ne[i]);
   }
       for (i=0;i<q;i++)
       {
           do
           for (j=(i+1);j<q;j++)
           {

               if (strcmp(ne[i],old[j])==0)
               {
                   j--;
                   x++;
                   strcpy(ne[i],ne[j]);

                   for (k=j;k<(q-1);k++)
                   {
                       ne[k]=ne[k+1];
                       old[k]=old[k+1];
                   }
               }
           }
       }

printf("%d\n",q-x);
for (i=0;i<(q-x);i++)
    printf("%s %s \n",old[i],ne[i]);

return 0;

}


//codeforces

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char* func(int i);
char* a[1001],*b[1001];
int c[1001]={0};
int main()
{
    char str[21];
    int q,i;
    scanf("%d",&q);
    getchar();
    for(i=0;i<q;i++)
    {
    a[i]=(char*)malloc(21*sizeof(char));
    b[i]=(char*)malloc(21*sizeof(char));
    scanf("%s %s",a[i],b[i]);
    }
    for(i=(q-1);((i>=0)&&(c[i]==0));i--)
    {
    printf("%s %s",func(i),b[i]);
    }
    return 0;

}

char* func(int i)
{
    int flag=0,j;
for(j=(i-1);j>=0;j--)
{
if(b[j]=a[i])
    {
        flag=1;
        break;
    }
}
  printf("%s",a[i]);
if(flag==0)
    return a[i];
else
    {
        c[j]=1;
        return func(j);
    }
}


#include<bits/stdc++.h>

using namespace std;

int find(int arr[],int p)
{
	if(arr[p]==-1)
	{
		return p;
	}
	int a=find(arr,arr[p]);
	arr[p]=a;
	return a;
}

int main()
{
	int n;
	cin>>n;
	int arr[n+1];
	fill_n(arr,n+1,-1);
	int a,b;
	map<int,vector<int>> res;
	for(int i=1;i<=n;i++)
	{
		res.insert(pair<int,vector<int>>(i,{i}));
	}
	for(int i=0;i<n-1;i++)
	{
		cin>>a>>b;
		int fa=find(arr,a);
		int fb=find(arr,b);

			if(fa<fb)
			{
				arr[fa]=fb;
				res[fb].insert(res[fb].end(),res[fa].begin(),res[fa].end());
				res.erase(fa);
			}
			else if(fb<fa)
			{
				arr[fb]=fa;
				res[fa].insert(res[fa].end(),res[fb].begin(),res[fb].end());
				res.erase(fb);
			}
		//printArr(arr,n+1);
	}

	map<int,vector<int>>::iterator i=res.begin();
	for(;i!=res.end();i++)
	{
		//cout<<"key="<<i->first<<" ";
		for(int k : i->second)
		{
			cout<<k<<" ";
		}
	}
}

/*

void printArr(int arr[],int n)
{
	for(int i=1;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}*/


#include<bits/stdc++.h>

using namespace std;

/*void printArr(int arr[],int n)
{
	for(int i=1;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;
}*/

int find(int arr[],int p)
{
	if(arr[p]==-1)
	{
		return p;
	}
	int a=find(arr,arr[p]);
	arr[p]=a;
	return a;
	/*while(arr[p]!=-1)
	{
		p=arr[p];
	}
	return p;*/
}

int main()
{
int n;
cin>>n;
int arr[n+1];
fill_n(arr,n+1,-1);
int a,b;
map<int,vector<int>> res;
for(int i=1;i<=n;i++)
{
	res.insert(pair<int,vector<int>>(i,{i}));
}
for(int i=0;i<n-1;i++)
{
	cin>>a>>b;
	int fa=find(arr,a);
	int fb=find(arr,b);

		if(fa<fb)
		{
			arr[fa]=fb;
			res[fb].insert(res[fb].end(),res[fa].begin(),res[fa].end());
			res.erase(fa);
		}
		else if(fb<fa)
		{
			arr[fb]=fa;
			res[fa].insert(res[fa].end(),res[fb].begin(),res[fb].end());
			res.erase(fb);
		}
	//printArr(arr,n+1);
}

map<int,vector<int>>::iterator i=res.begin();
for(;i!=res.end();i++)
{
	//cout<<"key="<<i->first<<" ";
	for(int k : i->second)
	{
		cout<<k<<" ";
	}
}

}