Problem: 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

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		ContestScanner in = new ContestScanner();
		int q = in.nextInt();
		HashMap<String, String> map = new HashMap<String, String>();
		HashSet<String> used = new HashSet<String>();
		for(int i=0; i<q; i++){
			String oldN = in.nextToken();
			String newN = in.nextToken();
			
			if(map.containsKey(oldN) && !used.contains(newN)){
				String oldest = map.get(oldN);
				map.remove(oldN);
				map.put(newN, oldest);
			}else{
				if(!used.contains(newN))
					map.put(newN, oldN);
			}
			used.add(oldN);
			used.add(newN);
		}
		System.out.println(map.size());
		for(Map.Entry<String, String> e : map.entrySet()){
			System.out.println(e.getValue()+" "+e.getKey());
		}
	}
	
}
//
//class Data{
//	String oldest;
//	String newN;
//	
//}
//
//class MyComp implements Comparator<int[]>{
//	public int compare(int[] a, int[] b) {
//		return a[0] - b[0];
//	}
//}
//
//class Reverse implements Comparator<Integer>{
//	public int compare(Integer arg0, Integer arg1) {
//		return arg1 - arg0;
//	}
//}

class Node{
	int id;
	List<Node> edge = new ArrayList<Node>();
	public Node(int id){
		this.id = id;
	}
	public void createEdge(Node node){
		edge.add(node);
	}
}
//
//
//class NodeW{
//	int id;
//	List<NodeW> edge = new ArrayList<NodeW>();
//	List<Integer> costList = new ArrayList<Integer>();
//	public NodeW(int id) {
//		this.id = id;
//	}
//	public void createEdge(NodeW node, int cost) {
//		edge.add(node);
//		costList.add(cost);
//	}
//}

class Range<T extends Comparable<T>> implements Comparable<Range<T>>{
	T start;
	T end;
	public Range(T start, T end){
		this.start = start;
		this.end = end;
	}
	public boolean inRange(T val){
		if(start.compareTo(val) <= 0 && end.compareTo(val) >= 0){
			return true;
		}
		return false;
	}
	public boolean isCommon(Range<T> range){
		if(inRange(range.start) || inRange(range.end) || range.inRange(start)){
			return true;
		}
		return false;
	}
	public Range<T> connect(Range<T> range){
		if(!isCommon(range)) return null;
		Range<T> res = new Range<T>(start.compareTo(range.start) <= 0 ? start : range.start,
				end.compareTo(range.end) >= 0 ? end : range.end);
		return res;
	}
	public boolean connectToThis(Range<T> range){
		if(!isCommon(range)) return false;
		start = start.compareTo(range.start) <= 0 ? start : range.start;
		end = end.compareTo(range.end) >= 0 ? end : range.end;
		return true;
	}
	@Override
	public int compareTo(Range<T> range) {
		int res = start.compareTo(range.start);
		if(res == 0) return end.compareTo(range.end);
		return res;
	}
	public String toString(){
		return "["+start+","+end+"]";
	}
}

class RangeSet<T extends Comparable<T>>{
	TreeSet<Range<T>> ranges = new TreeSet<Range<T>>();
	public void add(Range<T> range){
		Range<T> con = ranges.floor(range);
		if(con != null){
			if(con.connectToThis(range))
				range = con;
		}
		con = ranges.ceiling(range);
		while(con != null && range.connectToThis(con)){
			ranges.remove(con);
			con = ranges.ceiling(range);
		}
		ranges.add(range);
	}
	public String toString(){
		StringBuilder bld = new StringBuilder();
		for(Range<T> r: ranges){
			bld.append(r+"\n");
		}
		return bld.toString();
	}
}


class MyMath{
	public final static double PIhalf = Math.PI/2.0;
	public static double pAngle(double x, double y){
		// �x�N�g��(1, 0)��(x, y)�Ƃ̂Ȃ��p��Ԃ�(rad:0 to 2pi)
		if(x == 0){
			if(y == 0){
				System.err.println("pAngle error: zero vector.");
				return 0;
			}else if(y < 0){
				return PIhalf*3.0;
			}else{
				return PIhalf;
			}
		}
		double rad = Math.atan(y/x);
		if(rad < 0){
			rad += Math.PI*2.0;
		}
		return rad;
	}
	public static long fact(long n){
		long res = 1;
		while(n > 0){
			res *= n--;
		}
		return res;
	}
	public static long[][] pascalT(int n){
		long[][] tri = new long[n][];
		for(int i=0; i<n; i++){
			tri[i] = new long[i+1];
			for(int j=0; j<i+1; j++){
				if(j == 0 || j == i){
					tri[i][j] = 1;
				}else{
					tri[i][j] = tri[i-1][j-1] + tri[i-1][j];
				}
			}
		}
		return tri;
	}

	// �ő����
	static int gcd(int a, int b){
		return b == 0 ? a : gcd(b, a % b);
	}

	// �ŏ����{��
	static int lcm(int a, int b){
		return a * b / gcd(a, b);
	}
}

class ContestScanner{
	private BufferedReader reader;
	private String[] line;
	private int idx;
	public ContestScanner() throws FileNotFoundException{
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException{
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
	}
	
	public String nextToken() throws IOException{
		if(line == null || line.length <= idx){
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}
	public long nextLong() throws IOException, NumberFormatException{
		return Long.parseLong(nextToken());
	}
	public int nextInt() throws NumberFormatException, IOException{
		return (int)nextLong();
	}
	public double nextDouble() throws NumberFormatException, IOException{
		return Double.parseDouble(nextToken());
	}
}