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.util.*;
public class misha {
    public static void main(String[] args) {
        Scanner iangay = new Scanner(System.in);
        int numChanges = iangay.nextInt(), unique = 0;
        ArrayList<pair> changes = new ArrayList<>();
        HashMap<String, Integer> names = new HashMap<>();
        HashMap<Integer, String> namesr = new HashMap<>();
        int count = 0;
        for (int i = 0; i < numChanges; i++) {
            String f = iangay.next(), t = iangay.next();
            changes.add(new pair(f, t));
            if (!names.containsKey(f)) {
                namesr.put(count, f);
                names.put(f, count++);
            }
            if (!names.containsKey(t)) {
                namesr.put(count, t);
                names.put(t, count++);
            }
        }
//        System.out.println(names.toString());
        DSU dsu = new DSU(names.size());
        HashSet<String> init = new HashSet<>();
        for (pair p : changes) {
            if (dsu.size[names.get(p.k)] == 1) init.add(p.k);
            dsu.union(names.get(p.v), names.get(p.k));
        }
        System.out.println(init.size());
        for (String s : init) System.out.println(s+" "+namesr.get(dsu.find(names.get(s))));
    }
    static class DSU {
        int N;
        int[] parent, rank, size;
        DSU(int n) {
            N = n;
            parent = new int[N];
            rank = new int[N];
            size = new int[N];
            for (int i = 0; i < N; i++) {
                parent[i] = i;
                rank[i] = 1;
                size[i] = 1;
            }
        }
        int find(int v) { // average time O(logn)
            if (parent[v] == v) return v;
            return parent[v] = find(parent[v]);
        }
        void union(int a, int b) { // average time O(logn)
            a = find(a); b = find(b);
            parent[b] = a;
            size[a] += size[b];
            rank[a]++;
        }
    }

    static class pair implements Comparable<pair> {
        String k, v;
        pair(String k, String v) {
            this.k = k;
            this.v = v;
        }
        @Override
        public int compareTo(pair o) {
            if (!this.k.equals(o.k))
                return this.k.compareTo(o.k);
            return this.v.compareTo(o.v);
        }
        public String toString() {
            return "("+k+", "+v+")";
        }
    }
}