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;
struct prs {
  int s1, s2;
  prs operator+(prs u) const { return (prs){s1 + u.s1, s2 + u.s2}; }
  prs operator-(prs u) const { return (prs){s1 - u.s1, s2 - u.s2}; }
  void operator+=(prs u) { *this = *this + u; }
  bool operator<(prs u) const {
    if (s1 != u.s1) return s1 < u.s1;
    return s2 < u.s2;
  }
};
int n;
vector<pair<int, int> > G[100010];
int s[100010];
prs dp[100010][2];
prs ans[100010];
int ans1, ans2;
int to[100010];
int dep[100010];
int up[100010];
int m;
void solve(int x, int p) {
  dp[x][0] = dp[x][1] = (prs){0, 0};
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].first, id = G[x][i].second;
    if (id == p || id == m) continue;
    solve(y, id);
    dp[x][0] += max(dp[y][0], dp[y][1]);
  }
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].first, id = G[x][i].second;
    if (id == p || id == m) continue;
    prs t = (prs){1, s[x] != s[y]};
    prs val = dp[x][0] + dp[y][0] - max(dp[y][0], dp[y][1]) + t;
    if (dp[x][1] < val) dp[x][1] = val, to[x] = y;
  }
}
void getans(int x, int st, int p) {
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].first, id = G[x][i].second;
    if (id == p || id == m) continue;
    if (!st || to[x] != y) {
      if (dp[y][1] < dp[y][0])
        getans(y, 0, id);
      else
        getans(y, 1, id);
    } else {
      ans[++ans1] = (prs){x, y};
      if (s[x] != s[y]) ans2++;
      getans(y, 0, id);
    }
  }
}
void dfs(int x, int p) {
  dep[x]++;
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i].first, id = G[x][i].second;
    if (id == p) continue;
    if (!dep[y]) {
      up[y] = id;
      dep[y] = dep[x];
      dfs(y, id);
    } else if (dep[y] < dep[x]) {
      prs r1, r2;
      int s1, s2;
      m = id;
      solve(x, 0);
      if (dp[x][1] < dp[x][0])
        r1 = dp[x][0], s1 = 0;
      else
        r1 = dp[x][1], s1 = 1;
      m = up[x];
      solve(x, 0);
      if (dp[x][1] < dp[x][0])
        r2 = dp[x][0], s2 = 0;
      else
        r2 = dp[x][1], s2 = 1;
      if (r2 < r1) {
        m = id;
        solve(x, 0);
        getans(x, s1, 0);
      } else
        getans(x, s2, 0);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int f;
    scanf("%d%d", &f, s + i);
    G[f].push_back(make_pair(i, i));
    G[i].push_back(make_pair(f, i));
  }
  for (int i = 1; i <= n; i++) {
    if (dep[i]) continue;
    dfs(i, 0);
  }
  printf("%d %d\n", ans1, ans2);
  for (int i = 1; i <= ans1; i++) printf("%d %d\n", ans[i].s1, ans[i].s2);
  return 0;
}