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 = 110000;
int n;
struct Tinit {
  int f, u;
} A[maxn];
struct Tcxx {
  int A, B;
  Tcxx(int _A = 0, int _B = 0) { A = _A, B = _B; }
  inline bool operator<(const Tcxx &b) const {
    return A != b.A ? A < b.A : B < b.B;
  }
  inline Tcxx operator+(const Tcxx &b) const { return Tcxx(A + b.A, B + b.B); }
};
struct Talt {
  int tot;
  struct Tsqy {
    int s;
    Tsqy *l;
    inline void set(Tsqy *_l, int _s) { l = _l, s = _s; }
  } * pos[maxn], buf[maxn];
  inline void add(int a, int b) {
    buf[++tot].set(pos[a], b), pos[a] = buf + tot;
  }
} alt;
namespace Ninit {
void init() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d", &A[i].f, &A[i].u);
    --A[i].u, alt.add(A[i].f, i);
  }
}
}  // namespace Ninit
namespace Nsolve {
Tcxx ans;
vector<Tcxx> B;
bool U[maxn];
namespace Ntree {
Tcxx F[maxn][2];
int G[maxn];
vector<Tcxx> E;
void dfs(int x, int rt) {
  Talt::Tsqy *p;
  Tcxx ret;
  U[x] = true, F[x][0] = F[x][1] = Tcxx();
  for (p = alt.pos[x]; p; p = p->l)
    if (p->s != rt) {
      dfs(p->s, rt);
      F[x][1] = F[x][1] + max(F[p->s][0], F[p->s][1]);
      ret = F[x][0] + F[p->s][0] + Tcxx(1, A[x].u ^ A[p->s].u);
      if (F[x][1] < ret) F[x][1] = ret, G[x] = p->s;
      F[x][0] = F[x][0] + max(F[p->s][0], F[p->s][1]);
    }
}
void constrc(int x, int c, int rt) {
  Talt::Tsqy *p;
  for (p = alt.pos[x]; p; p = p->l)
    if (p->s != rt) {
      if (!c || p->s != G[x])
        constrc(p->s, F[p->s][0] < F[p->s][1] ? 1 : 0, rt);
      else
        E.push_back(Tcxx(x, p->s)), constrc(p->s, 0, rt);
    }
}
void solve(int x) {
  Tcxx Fc;
  int i;
  for (; !U[x]; x = A[x].f) U[x] = true;
  for (i = 0; i < 2; ++i, x = A[x].f) {
    dfs(x, x);
    if (Fc < F[x][1]) {
      Fc = F[x][1];
      E.clear(), constrc(x, 1, x);
    }
  }
  ans = ans + Fc, B.insert(B.end(), E.begin(), E.end());
}
}  // namespace Ntree
void solve() {
  int i;
  vector<Tcxx>::iterator p;
  for (i = 1; i <= n; ++i)
    if (!U[i]) Ntree::solve(i);
  printf("%d %d\n", ans.A, ans.B);
  for (p = B.begin(); p != B.end(); ++p) printf("%d %d\n", p->A, p->B);
}
}  // namespace Nsolve
int main() {
  Ninit::init();
  Nsolve::solve();
  return 0;
}