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 CPP):

Solution:
#include <bits/stdc++.h>
const int N = 200010;
int tot = 0, t = 0, l, r, u, first[N], s[N], f[N][3], w[N][3], k[N][3];
bool vis[N];
struct data {
  int y, next;
} g[N * 2];
struct data2 {
  int x, y;
} ans[N];
void add(int x, int y) {
  tot++;
  g[tot].y = y;
  g[tot].next = first[x];
  first[x] = tot;
}
void dfs(int x, int father) {
  vis[x] = true;
  for (int i = first[x]; i; i = g[i].next)
    if (!vis[g[i].y])
      dfs(g[i].y, x);
    else if (g[i].y != father)
      if (i & 1) {
        l = x;
        r = g[i].y;
      } else {
        l = g[i].y;
        r = x;
      }
}
void dp(int x) {
  f[x][0] = f[x][1] = w[x][0] = w[x][1] = k[x][0] = k[x][1] = 0;
  for (int i = first[x]; i; i = g[i].next)
    if (i & 1 && g[i].y != r) {
      dp(g[i].y);
      f[x][0] += f[g[i].y][2];
      w[x][0] += w[g[i].y][2];
    }
  for (int i = first[x]; i; i = g[i].next)
    if (i & 1 && g[i].y != r && g[i].y != u) {
      int tf = f[x][0] - f[g[i].y][2] + f[g[i].y][0] + 1,
          tw = w[x][0] - w[g[i].y][2] + w[g[i].y][0] + (s[x] != s[g[i].y]);
      if (f[x][1] < tf || (f[x][1] == tf && w[x][1] < tw)) {
        f[x][1] = tf;
        w[x][1] = tw;
        k[x][1] = g[i].y;
      }
    }
  if (x == u) f[x][1] = -1;
  if (f[x][0] > f[x][1] || (f[x][0] == f[x][1] && w[x][0] > w[x][1])) {
    f[x][2] = f[x][0];
    w[x][2] = w[x][0];
    k[x][2] = 0;
  } else {
    f[x][2] = f[x][1];
    w[x][2] = w[x][1];
    k[x][2] = 1;
  }
}
void get(int x, int kind) {
  if (kind == 2) kind = k[x][2];
  if (kind == 1 && k[x][1] != 0) {
    t++;
    ans[t].x = x;
    ans[t].y = k[x][1];
  }
  for (int i = first[x]; i; i = g[i].next)
    if (i & 1 && g[i].y != r)
      if (kind == 1 && g[i].y == k[x][1])
        get(g[i].y, 0);
      else
        get(g[i].y, 2);
}
int main() {
  int n, x, i, e = 0, tf, tw;
  scanf("%d", &n);
  memset(first, 0, sizeof(first));
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &x, &s[i]);
    add(x, i);
    add(i, x);
  }
  memset(vis, false, sizeof(vis));
  for (i = 1; i <= n; i++)
    if (!vis[i]) {
      dfs(i, 0);
      u = 0;
      dp(r);
      tf = f[r][2];
      tw = w[r][2];
      u = l;
      dp(r);
      if (tf < f[r][0] + 1 ||
          (tf == f[r][0] + 1 && tw < w[r][0] + (s[l] != s[r]))) {
        e += w[r][0] + (s[l] != s[r]);
        t++;
        ans[t].x = l;
        ans[t].y = r;
        get(r, 0);
      } else {
        e += tw;
        u = 0;
        dp(r);
        get(r, k[r][2]);
      }
    }
  printf("%d %d\n", t, e);
  for (i = 1; i <= t; i++) printf("%d %d\n", ans[i].x, ans[i].y);
  return (0);
}