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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;


public class CF501B {

	static ArrayList<Integer>[] adjList;
	static boolean[] visited;
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int q = sc.nextInt();
		int p = 0;
		HashMap<String, Integer> map = new HashMap<>();
		HashMap<Integer, String> inverse = new HashMap<>();
		ArrayList<Pair> list = new ArrayList<>();
		while(q-->0){
			String from = sc.next();
			String to = sc.next();
			int f;
			if(map.containsKey(from))
				f = map.get(from);
			else{
				f = p++;
				map.put(from, f);
				inverse.put(f, from);
			}
			int t = p++;
			map.put(to, t);
			inverse.put(t, to);
			list.add(new Pair(f,t));
		}
		visited = new boolean[p];
		adjList = new ArrayList[p];
		for (int i = 0; i < p; i++) {
			adjList[i] = new ArrayList<>();
		}
		for (int i = 0; i < list.size(); i++) {
			Pair pp = list.get(i);
			adjList[pp.x].add(pp.y);
		}
		int c = 0;
		ArrayList<String> output = new ArrayList<>();
		for (int i = 0; i < p; i++) {
			if(!visited[i])
			{
				c++;
				String from = inverse.get(i);
				String to = inverse.get(dfs(i));
				output.add(from + " " + to);
			}
		}
		pw.println(c);
		for (int i = 0; i < c; i++) {
			pw.println(output.get(i));
		}
		pw.flush();
	}

	private static int dfs(int i) {
		visited[i] = true;
		if(adjList[i].size() == 0)
			return i;
		else
			return dfs(adjList[i].get(0));
	}

	static class Pair{
		int x,y;
		public Pair(int x, int y){
			this.x = x;
			this.y = y;
		}
	}
	
	static class FastScanner {
		StringTokenizer st;
		BufferedReader br;

		public FastScanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastScanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}