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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
import javax.swing.RowFilter;

public class Main {

    public static void main(String[] args) throws IOException {
        //http://codeforces.com/contest/501/problem/B
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        StringBuilder sb = new StringBuilder();
        int q = Integer.parseInt(tokenizer.nextToken());
        HashMap<String, String> map = new HashMap<>();
        for (int i = 0; i < q; i++) {
            tokenizer = new StringTokenizer(reader.readLine());
            String old = tokenizer.nextToken();
            String niew = tokenizer.nextToken();
            label:
            {
                for (Map.Entry<String, String> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (key.equals(niew)) {
                        map.entrySet().remove(entry);
                        map.put(old, value);
                        break label;
                    }
                    if (value.equals(old)) {
                        map.entrySet().remove(entry);
                        map.put(key, niew);
                        break label;
                    }
                }
                map.put(old, niew);
            }
        }
        sb.append(map.size()).append("\n");
        for (String key : map.keySet()) {
            sb.append(key).append(" ").append(map.get(key)).append("\n");
        }
        System.out.println(sb.toString().trim());
    }

    private static int Log(int n, int base) {
        int sum = 0;
        while (n > 0) {
            sum++;
            n /= base;
        }
        return sum - 1;
    }

    static BigInteger[] Dp2Combination(int N) {
        int i, j;
        BigInteger[] Combination = new BigInteger[N + 1];
        for (i = 0; i <= N/**/ / 2; i++) {
//            for (j = i; j >= 0; j--) {
//                if (j == 0 || j == i) {
//                    Combination[ j] = 1;
//                } else {
//                    Combination[ j] = Combination[ j] + Combination[ j - 1];
//                }
//            }
            Combination[i] = Algorithm.C(new BigInteger(String.format("%d", N)), new BigInteger(String.format("%d", i)));
        }
        return Combination;
    }

    private static long[] Fib(int i) {
        long[] a = new long[i];
        a[0] = a[1] = 1;
        for (int j = 2; j < i; j++) {
            a[j] = a[j - 1] + a[j - 2];
        }
        return a;


    }

    static class Algorithm {

        static class MyString {

            static int NumberOfIterations(String str, String p) {
                int sum = 0;

                int index = 0;
                while (true) {
                    int temp = str.substring(index).indexOf(p);
                    if (temp >= 0) {
                        index += (temp + p.length());
                        sum++;
                    } else {
                        break;
                    }
                }

                return sum;
            }
        }

        static HashSet<Integer> NumbersFrom(String digitsString) {
            int[] digits = new int[10];
            for (int i = digitsString.length() - 1; i >= 0; i--) {
                if (digitsString.charAt(i) >= '0' && digitsString.charAt(i) <= '9') {
                    digits[digitsString.charAt(i) - '0']++;
                }
            }
            return NumbersFrom(digits);
        }

        static HashSet<Integer> NumbersFrom(int[] digits) {
            int maxDigit = 0;
            for (int i = 0; i < digits.length; i++) {
                maxDigit += digits[i];
            }
            return NumbersFrom(digits, maxDigit);
        }

        static HashSet<Integer> NumbersFrom(int[] digits, int maxDigit) {
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (int i = 0; i < digits.length; i++) {
                if (digits[i] > 0) {
                    list.add(i);
                }
            }
            int t1 = 0;
            int t2 = list.size();
            for (int i = 1; i < maxDigit; i++) {
                for (int j = t1; j < t2; j++) {
                    int number = list.get(j);
                    int temp = number;
                    while (temp > 0) {
                        digits[temp % 10]--;
                        temp /= 10;
                    }

                    for (int k = 0; k < 10; k++) {
                        if (digits[k] > 0) {
                            list.add(number * 10 + k);
                        }
                    }
                    while (number > 0) {
                        digits[number % 10]++;
                        number /= 10;
                    }
                }
                t1 = t2;
                t2 = list.size();
            }
            HashSet<Integer> set = new HashSet<Integer>(list);

            return set;
        }

        static long C(int n, int r) {
            if (n == 0) {
                return 1;
            }
            if (r == 0) {
                return 1;
            }
            if (n == r) {
                return 1;
            }
            if (r < n / 2) {
                return C(n, n - r);
            }
            return ZarbeMotevali(r + 1, n) / Fact(n - r);
        }

        static BigInteger C(BigInteger n, BigInteger r) {
            if (n.compareTo(new BigInteger("0")) == 0) {
                return new BigInteger("1");
            }
            if (r.compareTo(new BigInteger("0")) == 0) {
                return new BigInteger("1");
            }
            if (n.compareTo(r) == 0) {
                return new BigInteger("1");
            }
            if (r.compareTo(n.divide(new BigInteger("2"))) < 0) {
                return C(n, n.add(r.multiply(new BigInteger("-1"))));
            }
            return ZarbeMotevali(r.add(new BigInteger("1")), n).divide(ZarbeMotevali(new BigInteger("1"), n.add(r.multiply(new BigInteger("-1")))));
        }

        private static long ZarbeMotevali(int first, int end) {
            long answer = 1;
            for (long i = first; i <= end; i++) {
                answer *= i;
            }
            return answer;
        }

        private static BigInteger ZarbeMotevali(BigInteger first, BigInteger end) {
            BigInteger answer = new BigInteger("1");
            for (BigInteger i = new BigInteger(first.toString()); i.compareTo(end) <= 0; i = i.add(new BigInteger("1"))) {
                answer = answer.multiply(i);
            }
            return answer;
        }

        private static long Fact(int n) {
            return ZarbeMotevali(2, n);
        }

        static int GCD(int m, int n) {
            if (n > m) {
                return GCD(n, m);
            }
            if (m % n == 0) {
                return n;
            }
            return GCD(n, m % n);
        }

        static long GCD(long m, long n) {
            if (n > m) {
                return GCD(n, m);
            }
            if (m % n == 0) {
                return n;
            }
            return GCD(n, m % n);
        }

        static long LCM(long m, long n) {
            return (m * n) / GCD(m, n);
        }

        static int LCM(int m, int n) {
            return (m * n) / GCD(m, n);
        }

        static boolean IsPrime(long a) {
            if (a < 2) {
                return false;
            }
            if (a > 2 && a % 2 == 0) {
                return false;
            }
            long temp = (long) Math.sqrt(a);
            for (long i = 3; i <= temp; i += 2) {
                if (a % i == 0) {
                    return false;
                }
            }
            return true;
        }

        static int BinarySearch(int[] a, int start, int end, int value) {
            if (start == end) {
                return -1; // invalid index
            }
            int mid = (end + start) / 2;
            if (a[mid] == value) {
                return mid;
            }
            if (a[mid] < value) {
                return BinarySearch(a, mid + 1, end, value);
            }
            return BinarySearch(a, start, mid, value);
        }
    }
}

class MyPoint {

    double x;
    double y;

    public MyPoint(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public double distance(MyPoint point) {
        return Math.sqrt(Math.pow(this.x - point.x, 2) + Math.pow(this.y - point.y, 2));
    }

    public void change(double newX, double newY) {
        this.x = newX;
        this.y = newY;
    }
}

class Graph {

    private int[][] matrix;

    public Graph(int[][] matrix) {
        this.matrix = matrix;
    }

    class SortestPath {

        private int minDistance(long[] dist, boolean[] sptSet) {
            // Initialize min value
            long min = Long.MAX_VALUE;
            int minIndex = 0;

            for (int i = 0; i < matrix.length; i++) {
                if (sptSet[i] == false && dist[i] <= min) {
                    min = dist[i];
                    minIndex = i;
                }
            }

            return minIndex;
        }

        public long[] Dijkstra(int src) {
            int n = matrix.length;
            long[] dist = new long[n];

            boolean[] sptSet = new boolean[n];
            Arrays.fill(dist, Long.MAX_VALUE);
            Arrays.fill(sptSet, false);

            dist[src] = 0;

            for (int count = 0; count < n - 1; count++) {
                int u = minDistance(dist, sptSet);

                sptSet[u] = true;

                for (int i = 0; i < n; i++) {
                    if (!sptSet[i] && matrix[u][i] != 0 && dist[u] != Long.MAX_VALUE
                            && dist[u] + matrix[u][i] < dist[i]) {
                        dist[i] = dist[u] + matrix[u][i];
                    }
                }
            }
            return dist;
        }
    }

    class MST {

        class Prim {

            private boolean[] Visited;
            //private 
        }
    }

    class DFS {

        private Stack<Integer> DFS;
        private boolean[] visited;

        public DFS() {
            this.DFS = new Stack<Integer>();
            this.visited = new boolean[matrix.length];
        }

        public Stack<Integer> getDFS() {
            this.DFS(0);
            return DFS;
        }

        public Stack<Integer> getDFS(int vertex) {
            this.DFS.clear();
            this.DFS(vertex);
            return this.DFS;
        }

        private void DFS(int vertrx) {
            this.DFS.push(vertrx);
            this.visited[vertrx] = true;

            for (int i = 0; i < matrix[vertrx].length; i++) {
                if (matrix[vertrx][i] != 0 && !this.visited[i] && vertrx != i) {
                    this.DFS(i);
                }
            }
        }
    }
}

class ArithmeticProgression {

    long d;
    long a1;

    public ArithmeticProgression(long a1, long d) {
        this.d = d;
        this.a1 = a1;
    }

    public ArithmeticProgression(long a, long index, long d) {
        this.d = d;
        this.a1 = a - ((index - 1) * d);
    }

    long Term(long n) {
        return this.a1 + ((n - 1) * this.d);
    }

    long S(long n) {
        return S(1, n);
    }

    long S(long m, long n) {
        return ((n - m + 1) * (Term(m) + Term(n))) / 2;
    }
}

class FastScanner {

    private InputStream stream;
    private byte[] buffer = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream) {
        this.stream = stream;
    }

    int read() {
        if (numChars == -1) {
            throw new InputMismatchException();
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buffer);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buffer[curChar++];
    }

    boolean isWhiteSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    boolean isEndline(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

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

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

    float nextFloat() {
        return Float.parseFloat(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        int c = read();
        while (isWhiteSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isWhiteSpaceChar(c));
        return res.toString();
    }

    String nextLine() {
        int c = read();
        while (isEndline(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndline(c));
        return res.toString();
    }
}