Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Examples

Input

5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov


Output

3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123
import java.io.*;
import java.util.*;
import java.math.*;
public class cf {
	public static Scanner I=new Scanner(System.in);


	public static void BMishaAndChangingHandles() {
		HashMap<String,String> hm=new HashMap <String,String> ();
		int q=I.nextInt();
		for(int i=0; i<q; i++) {
			String old=I.next();
			String newStr=I.next();
			boolean found=false;
			for(Map.Entry<String,String>entry: hm.entrySet()) {
				if(entry.getValue().equals(old)) {
					found=true;
					hm.put(entry.getKey(),newStr);
					break;
				}
			}
			if(!found) {
				hm.put(old,newStr);
			}
		}
		System.out.printf("%d\n",hm.size());
		for(Map.Entry<String,String>entry: hm.entrySet()) {
			System.out.printf("%s %s\n",entry.getKey(),entry.getValue());
		}
	}
	// 285
	public static void Acontest() {
		int a=I.nextInt();
		int b=I.nextInt();
		int c=I.nextInt();
		int d=I.nextInt();
		int misha=Math.max(3*a/10,a-a/250*c);
		int vasya=Math.max(3*b/10,b-b/250*d);
		if(misha>vasya) {
			System.out.printf("Misha\n");
		} else if(misha<vasya) {
			System.out.printf("Vasya\n");
		} else {
			System.out.printf("Tie\n");
		}
	}
	// 278
	//
	public static boolean contain8(String str) {
		return str.indexOf('8')!=-1;	
	}
	public static void GigaTower() {
		long a=I.nextLong();
		for(long i=1; i<=100; i++) {
			if(contain8(String.valueOf(a+i))) {
				System.out.printf("%d\n",i);
				break;
			}
		}
	}

	public static boolean isDebuggingField(int []A) {
		int []B=A.clone();
		Arrays.sort(B);
		//System.out.printf("%d %d %d %d\n",B[0],B[1],B[2],B[3]);
		return B[3]==3*B[0] && B[0]+B[3]==B[1]+B[2];
	}

	public static void printYes(int[]A,int n) {
		System.out.printf("YES\n");
		for(int i=n; i<4; i++) {
			System.out.printf("%d\n",A[i]);
		}
	}
	public static void CandyBoxes() {
		int n=I.nextInt();
		int []A=new int[4];
		if(n==0){
			System.out.printf("YES\n1\n1\n3\n3\n");
		} else if(n==1) {
			A[0]=I.nextInt();
			System.out.printf("YES\n%d\n%d\n%d\n",A[0],3*A[0],3*A[0]);
		} else if(n==2) {
			A[0]=I.nextInt();
			A[1]=I.nextInt();
			int min=Math.min(A[0],A[1]);
			for(int c=1; c<=min*3; c++) {
				A[2]=c;
				for(int d=1; d<=min*3; d++) {
					A[3]=d;
					if(isDebuggingField(A)) {
						printYes(A,n);
						break;
					}
				}
				if(isDebuggingField(A)) { //break outter loop
					break;
				}
			}
			if(!isDebuggingField(A)) {
				System.out.printf("NO\n");
			}
		} else if(n==3) {
			A[0]=I.nextInt();
			A[1]=I.nextInt();
			A[2]=I.nextInt();
			int min=Math.min(Math.min(A[0],A[1]),A[2]);
			for(int d=1; d<=min*3;d++) {
				A[3]=d;

				if(isDebuggingField(A)) {
					printYes(A,n);
					break;
				} 
		
			}
			if(!isDebuggingField(A)) {
				System.out.printf("NO\n");
			}

		} else if(n==4) {
			A[0]=I.nextInt();
			A[1]=I.nextInt();
			A[2]=I.nextInt();
			A[3]=I.nextInt();
			
			if(isDebuggingField(A)) {
				printYes(A,n);
			} else {
				System.out.printf("NO\n");
			}
		}
	}

	// 277
	public static void CalculatingFunction() {
		long n=I.nextLong();
		System.out.printf("%d\n",(long)Math.pow(-1.0,(double)n)*(long)Math.ceil(n/2.0));
	}


	public static void ZeroMatrix(int [][]A,int row,int col,int c) {
		
		for(int j=0; j<A[0].length; j++) {
			A[row][j]=c;
		}

		for(int i=0; i<A.length; i++) {
			A[i][col]=c;
		}
	}

	public static boolean sameMatrix(int [][]A, int [][]B) {
		for(int i=0; i<A.length; i++) {
			for(int j=0; j<A[0].length; j++) {
				if(A[i][j]!=B[i][j]) {
					return false;
				}
			}
		}
		return true;
	}
	public static void printMatrix(int [][]A) {
		for(int i=0; i<A.length; i++) {
			for(int j=0; j<A[0].length; j++) {
				System.out.printf("%d ",A[i][j]);
			}
			System.out.printf("\n");
		}
		
	}
	public static void OrinMatrix() {
		int m=I.nextInt();
		int n=I.nextInt();
		int [][]A=new int[m][n];
		int [][]B=new int[m][n];
		int [][]C=new int[m][n];
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				A[i][j]=I.nextInt();
				B[i][j]=1;
				C[i][j]=0;
			}
		}


		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) { 
				if(A[i][j]==0) {
					ZeroMatrix(B,i,j,0);				
				}
			}
		}
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				if(B[i][j]==1) {
					ZeroMatrix(C,i,j,1);
				}
			}
		}
		if(sameMatrix(A,C)) {
			System.out.printf("YES\n");	
			printMatrix(B);
		} else {
			System.out.printf("NO\n");
	
		}


	}
	// 276
	public static void Factory() {
		long a=I.nextLong();
		int m=I.nextInt();
		for(int i=0; i<m; i++) {
			if(a%m==0) {
				System.out.printf("Yes\n");
				return;
			}
			a+=a%m;
		}
		System.out.printf("No\n");
	}



	public static void ValuableResources() {
		int n=I.nextInt();
		int []x=new int[n];
		int []y=new int[n];
		for(int i=0; i<n; i++) {
			x[i]=I.nextInt();
			y[i]=I.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);
		int width=x[n-1]-x[0];
		int height=y[n-1]-y[0];
		int max=width>=height? width:height;
		System.out.printf("%d\n",(long)max*max);
	}

	public static void Bits() {
		int n=I.nextInt();
		for(int i=0; i<n; i++) {
			long l=I.nextLong();
			long r=I.nextLong();
			long maxBitCount=0;
			long maxBitNum=0;
			for(long j=l; j<=r; j++) {
				if(Long.bitCount(j)>maxBitCount) {
					maxBitCount=Long.bitCount(j);
					maxBitNum=j;
				}
			}
			System.out.printf("%d\n",maxBitNum);
		}
	}

	public static void reverse(int []A) {
		int i=0;
		int j=A.length-1;
		while(i<j) {
			int temp=A[i];
			A[i]=A[j];
			A[j]=temp;
			i++;
			j--;
		}
	}
	public static void MaximumValue() {
		int n=I.nextInt();
		int []A=new int[n];
		for(int i=0; i<n; i++) {
			A[i]=I.nextInt();
		}
		Arrays.sort(A);
		reverse(A);
		int max=0;
		for(int i=0; i<n; i++) {
			for(int j=i+1; j<n; j++) {
				if(A[i]%A[j]>max) {
					max=A[i]%A[j];
				}
			}
		}
		System.out.printf("%d\n",max);
	}
	// 275.5
    public static void swap(int[]A,int i, int j,StringBuilder str) {
        int temp=A[i];
        A[i]=A[j];
        A[j]=temp;
        str.append(String.format("%d %d\n",i,j));

    }

	public static void SwapSort() {
		int n=I.nextInt();
		int []A=new int[n];
		StringBuilder str=new StringBuilder();
		for(int i=0; i<n; i++) {
			A[i]=I.nextInt();
		}

		int count=0;
		for(int i=0; i<n; i++) {
			int minIndex=i;
			int min=A[i];
			for(int j=i+1; j<n; j++) {
				if(A[j]<min) {
					minIndex=j;
					min=A[j];
				}
			}
			if(i!=minIndex) {
				count++;
				swap(A,i,minIndex,str);
			}
		}
		System.out.printf("%d\n%s",count,str);
	}
	public static void BerSUBall() {
		int n=I.nextInt();
		int []A=new int[n];
		for(int i=0; i<n; i++) {
			A[i]=I.nextInt();
		}
		Arrays.sort(A);
		int m=I.nextInt();
		int []B=new int[m];
		for(int i=0; i<m; i++) {
			B[i]=I.nextInt();	
		} 
		Arrays.sort(B);
		int pair=0;
		int i=0;
		int j=0;
		while(i<n && j<m) {
			if(Math.abs(A[i]-B[j])<=1) {
				pair++;
				i++;
				j++;
			} else if (A[i]>B[j]) {
				j++;
			} else if (A[i]<B[j]) {
				i++;
			}
		}
		System.out.printf("%d\n",pair);

	}

	public static void GivenLengthandSumofDigits() {
		int m=I.nextInt();
		int s=I.nextInt();
		if(s>m*9 || (m>=2 && s==0)) {
			System.out.printf("-1 -1\n");
		} else if(m==1 && s==0) {
			System.out.printf("0 0\n");
		} else {

			//for max
			int div=s/9;
			int rem=s%9;
			char[]max=new char[m];
			int index=0;
			while(div>0) {
				max[index]='9';
				index++;
				div--;
			}
			if(rem!=0) {
				max[index]=Character.forDigit(rem,10);
				index++;
			}
			while(index<m) {
				max[index]='0';
				index++;
			}
			

			// for  min
			String min=new String(max);
			StringBuilder minsb=(new StringBuilder(min)).reverse();
			if(minsb.charAt(0)=='0') {
				minsb.setCharAt(0,'1');
				for(int i=1; i<minsb.length(); i++) {
					if(minsb.charAt(i)!='0') {
						minsb.setCharAt(i, (char)(minsb.charAt(i)-1));
						break;
					}
				}
			}
			

			System.out.printf("%s %s\n",new String(minsb),new String(max));

			
		}
	}
	public static void main(String[] args) {
		// 285
		//Acontest();
		BMishaAndChangingHandles();
		// 278
		//GigaTower();
		//CandyBoxes();
		
		// 277
		//CalculatingFunction();
		//OrinMatrix();
		// 276
		//Factory();
		//ValuableResources();
		//Bits();	
		//MaximumValue();
		// 277
		//SwapSort();
		//BerSUBall();
		//GivenLengthandSumofDigits();
	}
}
