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;
int v[100005], s[100005];
long long w[100005];
basic_string<int> e[100005];
bool vis1[100005];
int backedge, fb1, fb2;
bool inst[100005];
int adj(int i, int x) { return i == x ? v[x] : i; }
void dfs1(int x, int i) {
  vis1[x] = true;
  inst[x] = true;
  for (int j : e[x]) {
    if (i == j) continue;
    int y = adj(j, x);
    if (vis1[y]) {
      if (inst[y]) {
        backedge = j;
      }
    } else {
      dfs1(y, j);
    }
  }
  inst[x] = false;
}
long long dp[100005][2];
int nx[100005];
void dfs2(int x, int i) {
  nx[x] = -1;
  dp[x][0] = 0;
  long long vr = -123123123123123123ll;
  for (int j : e[x]) {
    if (i == j) continue;
    if (j == backedge) continue;
    int y = adj(j, x);
    dfs2(y, j);
    bool bad = y == fb1 || y == fb2;
    if (!bad) {
      dp[x][0] += max(dp[y][0], dp[y][1]);
      long long cand = dp[y][0] - max(dp[y][0], dp[y][1]) + w[j];
      if (cand > vr) {
        nx[x] = j;
        vr = cand;
      }
    } else {
      dp[x][0] += dp[y][0];
    }
  }
  dp[x][1] = dp[x][0] + vr;
}
void rekonstruisi(int x, int i, int st, basic_string<int>& gr) {
  if (x == fb1 || x == fb2) st = 1;
  if (st == 0 && dp[x][1] > dp[x][0]) {
    gr += nx[x];
    for (int j : e[x]) {
      if (i == j) continue;
      if (j == backedge) continue;
      int y = adj(j, x);
      if (j == nx[x]) {
        rekonstruisi(y, j, 1, gr);
      } else {
        rekonstruisi(y, j, 0, gr);
      }
    }
  } else {
    for (int j : e[x]) {
      if (i == j) continue;
      if (j == backedge) continue;
      int y = adj(j, x);
      rekonstruisi(y, j, 0, gr);
    }
  }
}
long long tezina(basic_string<int>& gr) {
  long long z = 0;
  for (int i : gr) z += w[i];
  return z;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i] >> s[i];
    e[v[i]] += i;
    e[i] += i;
  }
  for (int i = 1; i <= n; i++) {
    w[i] = 1000000 + (s[i] != s[v[i]]);
  }
  basic_string<int> global_ans;
  for (int i = 1; i <= n; i++) {
    if (!vis1[i]) {
      dfs1(i, -1);
      fb1 = fb2 = -1;
      dfs2(i, -1);
      basic_string<int> gr1;
      rekonstruisi(i, -1, 0, gr1);
      fb1 = backedge;
      fb2 = v[backedge];
      dfs2(i, -1);
      basic_string<int> gr2;
      rekonstruisi(i, -1, 0, gr2);
      gr2 += backedge;
      if (tezina(gr2) > tezina(gr1)) {
        swap(gr2, gr1);
      }
      global_ans += gr1;
    }
  }
  long long finalwt = tezina(global_ans);
  cout << finalwt / 1000000 << ' ' << finalwt % 1000000 << '\n';
  for (int i : global_ans) cout << i << ' ' << v[i] << '\n';
}