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>
using namespace std;
int n, m, k;
bool debug = false;
int sex[100005], fa[100005], root[3], dp[2][2][2][100005], rt, ans[2][100005],
    anst, anse;
bool bl[100005];
vector<int> mp[100005];
void ff(int x) {
  while (!bl[x]) {
    bl[x] = 1;
    x = fa[x];
  }
  root[2] = x;
  root[1] = fa[x];
}
void cal(int x, int answho) {
  bl[x] = 1;
  if (mp[x].size() == 0) return;
  for (int child : mp[x])
    if (child != rt) {
      cal(child, answho);
      dp[answho][0][0][x] +=
          max(dp[answho][1][0][child], dp[answho][0][0][child]);
      int msex = dp[answho][1][0][child] == dp[answho][0][0][child]
                     ? max(dp[answho][1][1][child], dp[answho][0][1][child])
                     : dp[answho][1][1][child];
      dp[answho][0][1][x] += msex;
    }
  for (int child : mp[x])
    if (child != rt) {
      int xx = dp[answho][0][0][x] -
               max(dp[answho][1][0][child], dp[answho][0][0][child]) +
               dp[answho][0][0][child] + 1;
      int msex = dp[answho][1][0][child] == dp[answho][0][0][child]
                     ? max(dp[answho][1][1][child], dp[answho][0][1][child])
                     : dp[answho][1][1][child];
      int yy = dp[answho][0][1][x] - msex + dp[answho][0][1][child] +
               (sex[x] != sex[child]);
      if (xx > dp[answho][1][0][x]) {
        dp[answho][1][0][x] = xx;
        dp[answho][1][1][x] = yy;
        ans[answho][x] = child;
      } else if (xx == dp[answho][1][0][x]) {
        if (yy > dp[answho][1][1][x]) {
          dp[answho][1][1][x] = yy;
          ans[answho][x] = child;
        }
      }
    }
}
vector<pair<int, int>> fans;
int who;
void pp(int x, bool u) {
  if (u) {
    if (dp[who][1][0][x] == dp[who][0][0][x] &&
        dp[who][1][1][x] < dp[who][0][1][x])
      u = false;
  }
  for (int child : mp[x])
    if (child != rt) {
      if (!u || child != ans[who][x])
        pp(child, true);
      else {
        fans.push_back({x, child});
        pp(child, false);
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", fa + i, sex + i);
    mp[fa[i]].push_back(i);
  }
  int qq;
  for (int i = 1; i <= n; i++)
    if (!bl[i]) {
      ff(i);
      rt = root[1];
      cal(rt, 0);
      rt = root[2];
      cal(rt, 1);
      bool u = true;
      if (dp[0][1][0][root[1]] != dp[1][1][0][root[2]]) {
        who = dp[0][1][0][root[1]] > dp[1][1][0][root[2]] ? 0 : 1;
      } else {
        if (dp[0][1][0][root[1]] == dp[0][0][0][root[1]]) {
          qq = 0;
        } else
          qq = 1;
        int ma = -1;
        for (int p = 0; p < 2; p++)
          for (int q = qq; q < 2; q++) {
            if (dp[p][q][1][root[p + 1]] > ma) {
              ma = dp[p][q][1][root[p + 1]];
              who = p;
              u = q == 1;
            }
          }
      }
      rt = root[who + 1];
      anst += dp[who][u ? 1 : 0][0][rt];
      anse += dp[who][u ? 1 : 0][1][rt];
      pp(rt, u);
    }
  printf("%d %d\n", anst, anse);
  for (auto p : fans) {
    printf("%d %d\n", p.first, p.second);
  }
  return 0;
}