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.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    private static Reader in;
    private static PrintWriter out;
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    private static int min(int... a){int min=a[0]; for(int i:a) min=Math.min(min, i); return min;}
    private static int max(int... a){int max=a[0]; for(int i:a) max=Math.max(max, i); return max;}
    private static long min(long... a){long min=a[0]; for(long i:a)min=Math.min(min, i); return min;}
    private static long max(long... a){long max=a[0]; for(long i:a)max=Math.max(max, i); return max;}
    private static String strm(String str, long m) {
        String ans="";
        while(m>0) {
            if(m%2==1) ans=ans.concat(str);
            str=str.concat(str); m>>=1;
        } return ans;
    }
    private static long mod(long a, long mod) {long res = a%mod; return res>=0 ? res : res+mod;}
    private static int mod(int a, int mod) {int res = a%mod; return res>=0 ? res : res+mod;}
    private static long modpow(long base, long exp, long mod) {
        return new BigInteger(Long.toString(base)).modPow(new BigInteger(Long.toString(exp)), new BigInteger(Long.toString(mod))).longValueExact();
    }
    private static int modpow(int x, int n, int mod) {
        int res = 1;
        for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
            if ((n & 1) != 0) {
                res = (int) (res * p % mod);
            }
        }
        return res;
    }
    private static long gcd(long a, long b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}
    private static int gcd(int a, int b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}
    private static long gcd(long... a) {long gcd=a[0]; for(long x:a) gcd=gcd(gcd, x); return gcd;}
    private static int gcd(int... a) {int gcd=a[0]; for(int x:a) gcd=gcd(gcd, x); return gcd;}
    private static class Pair {
        public int x, y;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
        @Override
        public boolean equals(Object obj) {
            if (obj == this) return true;
            if (!(obj instanceof Pair)) return false;
            Pair pair = (Pair)obj;
            return this.x == pair.x && this.y == pair.y;
        }

        @Override
        public int hashCode() {
            return (this.x+" "+this.y).hashCode();
        }
    }
    private static class Triplet {
        public int x, y, z;
        public Triplet(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
        @Override
        public boolean equals(Object obj) {
            if (obj == this) return true;
            if (!(obj instanceof Triplet)) return false;
            Triplet triplet = (Triplet)obj;
            return this.x == triplet.x && this.y == triplet.y && this.z == triplet.z;
        }

        @Override
        public int hashCode() {
            return (this.x+" "+this.y+" "+this.z).hashCode();
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    static class Reader {
        private BufferedReader br;
        private StringTokenizer token;
        protected Reader(FileReader obj) {
            br = new BufferedReader(obj, 32768);
            token = null;
        }
        protected Reader() {
            br = new BufferedReader(new InputStreamReader(System.in), 32768);
            token = null;
        }
        protected String next() {
            while(token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (Exception e) {e.printStackTrace();}
            } return token.nextToken();
        }
        protected String nextLine() {
            String str="";
            try {
                str = br.readLine();
            } catch (Exception e) {e.printStackTrace();}
            return str;
        }
        protected int nextInt() {return Integer.parseInt(next());}
        protected long nextLong() {return Long.parseLong(next());}
        protected double nextDouble() {return Double.parseDouble(next());}
        protected long[] nextLongArr(int n) {
            long[] arr = new long[n]; for(int i=0; i<n; i++) arr[i] = nextLong(); return arr;
        }
        protected int[] nextIntArr(int n) {
            int[] arr = new int[n]; for(int i=0; i<n; i++) arr[i] = nextInt(); return arr;
        }
    }
    static class Node<T> {
        T data;
        Node parent;
        int rank, setSize;
        boolean first, last;
    }
    static class DisjointSet<T> {

        private HashMap<T, Node> hm = new HashMap<>();
        int numOfSets=0;
        private void makeSet(T data) {
            if (isPresent(data)) return;
            Node node = new Node();
            node.parent = node;
            node.rank = 0;
            node.data = data;
            node.setSize = 1;
            node.first = true; node.last = true;
            hm.put(data, node);
            numOfSets++;
        }
        private void union(T data1, T data2) {
            if (!isPresent(data1)) makeSet(data1);
            if (!isPresent(data2)) makeSet(data2);
            Node node1 = hm.get(data1), node2 = hm.get(data2);
            Node parent1 = findSet(hm.get(data1)), parent2 = findSet(hm.get(data2));
            if (parent1.data == parent2.data) return;
            if (parent1.rank >= parent2.rank) {
                parent1.rank = parent1.rank == parent2.rank ? parent1.rank+1 : parent1.rank;
                parent2.parent = parent1;
                parent1.setSize += parent2.setSize;
            } else {
                parent1.parent = parent2;
                parent2.setSize += parent1.setSize;
            }
            node1.last = false; node2.first = false; node2.last = true;
            numOfSets--;
        }
        private boolean isPresent(T data) {
            return hm.containsKey(data);
        }
        private Node findSet(Node node) {
            Node parent = node.parent;
            if (parent == node) return parent;
            node.parent = findSet(node.parent);
            return node.parent;
        }
        private int setSize(T data) {
            if (!isPresent(data)) return 0;
            return findSet(hm.get(data)).setSize;
        }
    }
    private static void solve() {
        DisjointSet<String> ds = new DisjointSet<>();
        int q = in.nextInt();
        while (q-->0) {
            String s1 = in.next(), s2 = in.next();
            ds.makeSet(s1); ds.makeSet(s2); ds.union(s1, s2);
        }
        out.printf("%d\n", ds.numOfSets);
        HashMap<Node, ArrayList<String>> hashMap = new HashMap<>();
        for (Map.Entry<String, Node> entry : ds.hm.entrySet()) {
            Node parent = ds.findSet(entry.getValue());
            ArrayList<String> temp;
            if (hashMap.containsKey(parent)) temp = hashMap.get(parent);
            else temp = new ArrayList<>(Arrays.asList("", ""));
            if (entry.getValue().first) {
                temp.set(0, entry.getKey());
                hashMap.put(parent, temp);
            } else if (entry.getValue().last) {
                temp.set(1, entry.getKey());
                hashMap.put(parent, temp);
            }
        }
        for (Map.Entry<Node, ArrayList<String>> entry: hashMap.entrySet()) {
            out.printf("%s %s\n", entry.getValue().get(0), entry.getValue().get(1));
        }
    }
    public static void main(String[] args) throws IOException {
//        in = new Reader(new FileReader("C:\\Users\\Suhaib\\Desktop\\input.txt"));
//        out = new PrintWriter(new FileWriter("C:\\Users\\Suhaib\\Desktop\\output.txt"));
        in = new Reader();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
}