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;
const int maxn = 1e5 + 5;
vector<int> nei[maxn];
int sx[maxn], deg[maxn], que[maxn];
bool used[maxn], vis[maxn];
int U, V, frm[maxn];
pair<int, int> maxx[2][maxn];
void add(pair<int, int> &a, pair<int, int> b) {
  a.first += b.first;
  a.second += b.second;
  return;
}
void sub(pair<int, int> &a, pair<int, int> b) {
  a.first -= b.first;
  a.second -= b.second;
  return;
}
void clear(int rt, int f) {
  maxx[0][rt] = maxx[1][rt] = make_pair(0, 0);
  bool used = false;
  for (int i = 0; i < (int)nei[rt].size(); i++) {
    int to = nei[rt][i];
    if (to == f) continue;
    if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
      used = true;
      continue;
    }
    clear(to, rt);
  }
  return;
}
void slv(int rt, int f) {
  bool used = false;
  for (int i = 0; i < (int)nei[rt].size(); i++) {
    int to = nei[rt][i];
    if (to == f) continue;
    if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
      used = true;
      continue;
    }
    slv(to, rt);
    add(maxx[0][rt], maxx[1][to]);
  }
  maxx[1][rt] = maxx[0][rt];
  frm[rt] = -1;
  used = false;
  for (int i = 0; i < (int)nei[rt].size(); i++) {
    int to = nei[rt][i];
    if (to == f) continue;
    if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
      used = true;
      continue;
    }
    pair<int, int> cur = maxx[0][rt];
    sub(cur, maxx[1][to]);
    add(cur, maxx[0][to]);
    cur.first++;
    cur.second += (sx[rt] != sx[to]);
    if (cur > maxx[1][rt]) {
      maxx[1][rt] = cur;
      frm[rt] = to;
    }
  }
  return;
}
vector<pair<int, int> > out;
void wrk(int rt, int type, int f) {
  if (type == 1) {
    bool used = false;
    for (int i = 0; i < (int)nei[rt].size(); i++) {
      int to = nei[rt][i];
      if (to == f) continue;
      if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
        used = true;
        continue;
      }
      if (to == frm[rt])
        wrk(to, 0, rt);
      else
        wrk(to, 1, rt);
    }
    if (~frm[rt]) out.push_back(make_pair(frm[rt], rt));
  } else {
    bool used = false;
    for (int i = 0; i < (int)nei[rt].size(); i++) {
      int to = nei[rt][i];
      if (to == f) continue;
      if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
        used = true;
        continue;
      }
      wrk(to, 1, rt);
    }
  }
  return;
}
void tag(int rt, int f) {
  vis[rt] = true;
  bool used = false;
  for (int i = 0; i < (int)nei[rt].size(); i++) {
    int to = nei[rt][i];
    if (to == f) continue;
    if (((rt == U && to == V) || (rt == V && to == U)) && (used == false)) {
      used = true;
      continue;
    }
    tag(to, rt);
  }
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int f;
    scanf("%d%d", &f, &sx[i]);
    nei[f].push_back(i);
    nei[i].push_back(f);
    deg[i]++;
    deg[f]++;
  }
  int head = 0, tail = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      used[i] = true;
      que[tail++] = i;
    }
  }
  while (head < tail) {
    int cur = que[head++];
    for (int i = 0; i < (int)nei[cur].size(); i++) {
      int to = nei[cur][i];
      if ((--deg[to]) == 1) {
        used[to] = true;
        que[tail++] = to;
      }
    }
  }
  pair<int, int> ans = make_pair(0, 0);
  for (int i = 1; i <= n; i++) {
    if (used[i] || vis[i]) continue;
    int aim1 = -1, aim2 = -1;
    for (int j = 0; j < (int)nei[i].size(); j++) {
      int to = nei[i][j];
      if (used[to]) continue;
      if (~aim1)
        aim2 = to;
      else
        aim1 = to;
    }
    U = i;
    V = aim1;
    slv(i, 0);
    pair<int, int> ans1 = maxx[1][i];
    clear(i, 0);
    U = i;
    V = aim2;
    slv(i, 0);
    pair<int, int> ans2 = maxx[1][i];
    clear(i, 0);
    if (ans1 > ans2) {
      U = i;
      V = aim1;
    }
    slv(i, 0);
    add(ans, maxx[1][i]);
    clear(i, 0);
    wrk(i, 1, 0);
    tag(i, 0);
  }
  printf("%d %d\n", ans.first, ans.second);
  for (int i = 0; i < (int)out.size(); i++)
    printf("%d %d\n", out[i].first, out[i].second);
  return 0;
}