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 m, n, j, k, l, i, o, p, __t, sex[300000], cir1, cir2, kind;
bool solve[300000];
pair<int, int> ans;
vector<pair<pair<int, int>, pair<int, int> > > root;
vector<pair<int, int> > print;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  pair<int, int> c;
  c.first = a.first + b.first;
  c.second = a.second + b.second;
  return c;
}
bool operator>(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second > b.second;
}
char ch;
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
struct graph {
  int Be[300000], E[300000], N[300000], F[300000], T, L[300000], op, ed,
      Fa[300000], H[300000];
  int inque[300000], tl;
  int S[300000], ts;
  void make(int i, int j, int k) {
    N[++T] = Be[i];
    E[T] = j;
    Be[i] = T;
    if (k) make(j, i, 0);
  }
  int list[300000], lop, led;
  int linque[300000], tim, lin[300000];
  pair<int, int> dp[300000][2];
  pair<int, int> DP(int base, int forbiden1 = 0, int forbiden2 = 0,
                    int kind = 0) {
    linque[list[lop = led = 1] = base] = ++tim;
    Fa[base] = 0;
    for (int now = list[led]; led <= lop; led++, now = list[led]) {
      S[now] = ts;
      for (int i = Be[now]; i; i = N[i]) {
        int def = E[i];
        if ((def == forbiden1 || def == forbiden2) && (kind == 1)) continue;
        if ((now == forbiden1 && def == forbiden2) ||
            (now == forbiden2 && def == forbiden1))
          continue;
        if (def == Fa[now]) continue;
        linque[list[++lop] = def] = tim;
        Fa[def] = now;
      }
    }
    for (int z = lop; z > 0; z--) {
      int now = list[z];
      dp[now][0].first = dp[now][0].second = dp[now][1].first =
          dp[now][1].second = 0;
      lin[now] = 0;
      for (int i = Be[now]; i; i = N[i]) {
        int def = E[i];
        if ((def == forbiden1 || def == forbiden2) && (kind == 1)) continue;
        if ((now == forbiden1 && def == forbiden2) ||
            (now == forbiden2 && def == forbiden1))
          continue;
        if (def == Fa[now]) continue;
        pair<int, int> temp0 = dp[now][0], temp1 = dp[now][1];
        pair<int, int> a1 = temp0 + dp[def][0], a2 = temp1 + dp[def][1];
        a2.first++;
        a2.second += sex[now] ^ sex[def];
        if (a2 > a1) lin[now] = def;
        dp[now][0] = max(a1, a2);
        dp[now][1] = temp1 + max(dp[def][0], dp[def][1]);
      }
    }
    return max(dp[base][0], dp[base][1]);
  }
  void solved(int base) {
    inque[L[op = ed = 1] = base] = ++tl;
    Fa[base] = 0, H[base] = 0;
    bool have_cir = 0;
    int cir_p0, cir_p1;
    for (int now = L[ed]; ed <= op; ed++, now = L[ed]) {
      solve[now] = 1;
      for (int i = Be[now]; i; i = N[i])
        if (E[i] != Fa[now]) {
          if (inque[E[i]] != tl)
            inque[L[++op] = E[i]] = tl, H[E[i]] = H[now] + 1, Fa[E[i]] = now;
          else {
            have_cir = 1;
            cir_p0 = now;
            cir_p1 = E[i];
          }
        }
    }
    if (op == 2) {
      ans.first++;
      ans.second += sex[L[1]] ^ sex[L[2]];
      print.push_back(make_pair(L[1], L[2]));
      return;
    }
    ++ts;
    pair<int, int> u, z;
    u.first = u.second = 0;
    for (int i = 1; i <= op; i++)
      if (S[L[i]] != ts) {
        u = u + DP(L[i], cir_p0, cir_p1, 0);
      }
    ++ts;
    z.first = 1;
    z.second = sex[cir_p0] ^ sex[cir_p1];
    S[cir_p1] = S[cir_p0] = ts;
    for (int i = 1; i <= op; i++)
      if (S[L[i]] != ts) z = z + DP(L[i], cir_p0, cir_p1, 1);
    ++ts;
    if (u > z) {
      ans = ans + u;
      for (int i = 1; i <= op; i++)
        if (S[L[i]] != ts) {
          root.push_back(
              make_pair(make_pair(L[i], 0), make_pair(cir_p0, cir_p1)));
          u = u + DP(L[i], cir_p0, cir_p1, 0);
        }
    } else {
      ans = ans + z;
      S[cir_p0] = S[cir_p1] = ts;
      print.push_back(make_pair(cir_p0, cir_p1));
      for (int i = 1; i <= op; i++) {
        if (S[L[i]] != ts) {
          root.push_back(
              make_pair(make_pair(L[i], 1), make_pair(cir_p0, cir_p1)));
          z = z + DP(L[i], cir_p0, cir_p1, 1);
        }
      }
    }
  }
  void DFS(int now, int son) {
    if (son == 0 || (son == 1 && dp[now][0] <= dp[now][1])) {
      for (int i = Be[now]; i; i = N[i]) {
        int def = E[i];
        if ((def == cir1 || def == cir2) && (kind == 1)) continue;
        if ((now == cir1 && def == cir2) || (now == cir2 && def == cir1))
          continue;
        if (def == Fa[now]) continue;
        DFS(E[i], 1);
      }
    } else {
      print.push_back(make_pair(now, lin[now]));
      for (int i = Be[now]; i; i = N[i]) {
        int def = E[i];
        if ((def == cir1 || def == cir2) && (kind == 1)) continue;
        if ((now == cir1 && def == cir2) || (now == cir2 && def == cir1))
          continue;
        if (def == Fa[now]) continue;
        if (lin[now] == def)
          DFS(E[i], 0);
        else
          DFS(E[i], 1);
      }
    }
  }
} pic;
int main() {
  read(m);
  for (int i = 1; i <= m; i++) {
    read(j), read(k);
    pic.make(i, j, 1);
    sex[i] = k - 1;
  }
  for (int i = 1; i <= m; i++)
    if (!solve[i]) pic.solved(i);
  printf("%d %d\n", ans.first, ans.second);
  for (int i = 0; i < root.size(); i++) {
    cir1 = root[i].second.first;
    cir2 = root[i].second.second;
    kind = root[i].first.second;
    pic.DFS(root[i].first.first, 1);
  }
  for (int i = 0; i < print.size(); i++)
    printf("%d %d\n", print[i].first, print[i].second);
}