Problem: There are n students in Polycarp's class (including himself). A few days ago all students wrote an essay "My best friend". Each student's essay was dedicated to one of the students of class, to his/her best friend. Note that student b's best friend is not necessarily student a, if a's best friend is b.

And now the teacher leads the whole class to the museum of the history of sports programming. Exciting stories of legendary heroes await the students: tourist, Petr, tomek, SnapDragon — that's who they will hear about!

The teacher decided to divide students into pairs so that each pair consisted of a student and his best friend. She may not be able to split all the students into pairs, it's not a problem — she wants to pick out the maximum number of such pairs. If there is more than one variant of doing so, she wants to pick out the pairs so that there were as much boy-girl pairs as possible. Of course, each student must not be included in more than one pair.

Input

The first line contains an integer n (2 ≤ n ≤ 105), n is the number of students per class. Next, n lines contain information about the students, one per line. Each line contains two integers fi, si (1 ≤ fi ≤ n, fi ≠ i, 1 ≤ si ≤ 2), where fi is the number of i-th student's best friend and si denotes the i-th pupil's sex (si = 1 for a boy and si = 2 for a girl).

Output

Print on the first line two numbers t, e, where t is the maximum number of formed pairs, and e is the maximum number of boy-girl type pairs among them. Then print t lines, each line must contain a pair ai, bi (1 ≤ ai, bi ≤ n), they are numbers of pupils in the i-th pair. Print the pairs in any order. Print the numbers in pairs in any order. If there are several solutions, output any of them.

Examples

Input

5
5 2
3 2
5 1
2 1
4 2


Output

2 2
5 3
4 2


Input

6
5 2
3 2
5 1
2 1
4 2
3 1


Output

3 1
4 2
5 1
3 6


Input

8
2 2
3 2
5 1
3 1
6 1
5 1
8 2
7 1


Output

4 1
5 6
3 4
2 1
7 8

Note

The picture corresponds to the first sample. On the picture rhomb stand for boys, squares stand for girls, arrows lead from a pupil to his/her best friend. Bold non-dashed arrows stand for pairs in the answer. 

<image>

Solution (in JAVA):

Solution:
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class E {
    Scanner sc = new Scanner(System.in);
    
    void run() {
        int n = sc.nextInt();
        V[] vs = new V[n];
        for (int i = 0; i < n; i++) vs[i] = new V(i);
        for (int i = 0; i < n; i++) {
            vs[i].parent = vs[sc.nextInt() - 1];
            vs[i].parent.child.add(vs[i]);
            vs[i].sex = sc.nextInt();
        }
        int t = 0, e = 0;
        for (V v : vs) if (!v.used) {
            V root = v;
            while (!root.visit) {
                root.visit = true;
                root = root.parent;
            }
            v = root;
            do {
                v.loop = true;
                v = v.parent;
            } while (v != root);
            ArrayList<V> list = new ArrayList<E.V>();
            int m = 0;
            root.used = true;
            list.add(root);
            while (m < list.size()) {
                v = list.get(m++);
                for (V u : v.child) if (!u.used) {
                    u.used = true;
                    list.add(u);
                }
            }
            root.dp2[0][1] = root.dp2[1][0] = -(1L << 60);
            for (int i = list.size() - 1; i >= 0; i--) {
                v = list.get(i);
                if (v.loop) {
                    for (int j = 0; j < 2; j++) {
                        long sum = 0;
                        for (V u : v.child) {
                            if (u.loop) sum += max(u.dp2[j][0], u.dp2[j][1]);
                            else sum += max(u.dp[0], u.dp[1]);
                        }
                        v.dp2[j][0] = sum;
                        for (V u : v.child) {
                            if (u.loop) v.dp2[j][1] = max(v.dp2[j][1], sum + (1L << 32) + abs(v.sex - u.sex) + u.dp2[j][0] - max(u.dp2[j][0], u.dp2[j][1]));
                            else v.dp2[j][1] = max(v.dp2[j][1], sum + (1L << 32) + abs(v.sex - u.sex) + u.dp[0] - max(u.dp[0], u.dp[1]));
                        }
                    }
                } else {
                    long sum = 0;
                    for (V u : v.child) sum += max(u.dp[0], u.dp[1]);
                    v.dp[0] = sum;
                    for (V u : v.child) v.dp[1] = max(v.dp[1], sum + (1L << 32) + abs(v.sex - u.sex) + u.dp[0] - max(u.dp[0], u.dp[1]));
                }
            }
            int q;
            if (root.dp2[0][0] < root.dp2[1][1]) root.p = q = 1;
            else root.p = q = 0;
            t += (int)(root.dp2[q][root.p] >> 32);
            e += (int)(root.dp2[q][root.p]);
            for (int i = 0; i < list.size(); i++) {
                v = list.get(i);
                if (v.loop) {
                    for (V u : v.child) {
                        if (u.loop) {
                            if (u.dp2[q][0] < u.dp2[q][1]) {
                                u.p = 1;
                            } else {
                                u.p = 0;
                            }
                        } else {
                            if (u.dp[0] < u.dp[1]) {
                                u.p = 1;
                            } else {
                                u.p = 0;
                            }
                        }
                    }
                    if (v.p == 1) {
                        for (V u : v.child) {
                            if (u.loop) {
                                if (v.dp2[q][1] == v.dp2[q][0] + (1L << 32) + abs(v.sex - u.sex) + u.dp2[q][0] - max(u.dp2[q][0], u.dp2[q][1])) {
                                    u.p = 0;
                                    v.pair = u;
                                    u.pair = v;
                                    break;
                                }
                            } else {
                                if (v.dp2[q][1] == v.dp2[q][0] + (1L << 32) + abs(v.sex - u.sex) + u.dp[0] - max(u.dp[0], u.dp[1])) {
                                    u.p = 0;
                                    v.pair = u;
                                    u.pair = v;
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    for (V u : v.child) {
                        if (u.dp[0] < u.dp[1]) {
                            u.p = 1;
                        } else {
                            u.p = 0;
                        }
                    }
                    if (v.p == 1) {
                        for (V u : v.child) {
                            if (v.dp[1] == v.dp[0] + (1L << 32) + abs(v.sex - u.sex) + u.dp[0] - max(u.dp[0], u.dp[1])) {
                                u.p = 0;
                                v.pair = u;
                                u.pair = v;
                                break;
                            }
                        }
                    }
                }
                if (i == 0) {
                    root.dp2 = new long[2][2];
                    root.dp2[0][1] = root.dp2[1][0] = -(1L << 60);
                }
            }
        }
        System.out.println(t + " " + e);
        for (int i = 0; i < n; i++) if (vs[i].pair != null && vs[i].pair.id > i) {
            System.out.println((i + 1) + " " + (vs[i].pair.id + 1));
        }
    }
    
    class V {
        ArrayList<V> child = new ArrayList<V>();
        V parent;
        int id, sex;
        boolean used, visit, loop;
        long[] dp = new long[2];
        long[][] dp2 = new long[2][2];
        V pair = null;
        int p;
        V(int id) {
            this.id = id;
        }
    }
    
    class Scanner {
        BufferedReader br;
        StringTokenizer st;
        Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            eat("");
        }
        void eat(String s) {
            st = new StringTokenizer(s);
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new IOError(e);
            }
        }
        boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null) return false;
                eat(s);
            }
            return true;
        }
        String next() {
            hasNext();
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    
    void debug(Object...os) {
        System.err.println(deepToString(os));
    }
    
    public static void main(String[] args) {
        new E().run();
    }
}