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 + 20;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first - b.first, a.second - b.second);
}
int N, root, s[maxn], dad[maxn], ch[maxn];
bool used[maxn];
pair<int, int> dn[maxn][2], res;
vector<int> veled[maxn];
vector<pair<int, int> > ansv;
void dfs(int node) {
  used[node] = 1;
  for (__typeof(veled[node].begin()) it = veled[node].begin();
       it != veled[node].end(); it++) {
    int x = *it;
    if (x == root) continue;
    dfs(x);
    dn[node][0] = dn[node][0] + max(dn[x][1], dn[x][0]);
    pair<int, int> t =
        dn[x][0] + pair<int, int>(1, s[node] ^ s[x]) - max(dn[x][0], dn[x][1]);
    if (dn[node][1] < t) dn[node][1] = t, ch[node] = x;
  }
  dn[node][1] = dn[node][1] + dn[node][0];
}
void rem(int node) {
  dn[node][0] = dn[node][1] = pair<int, int>(0, 0);
  for (__typeof(veled[node].begin()) it = veled[node].begin();
       it != veled[node].end(); it++) {
    int x = *it;
    if (x == root) continue;
    rem(x);
  }
}
void yaz(int, int);
void f(int node) {
  if (dn[node][0] < dn[node][1])
    yaz(node, 1);
  else
    yaz(node, 0);
}
void yaz(int node, int mark) {
  if (mark) ansv.push_back(pair<int, int>(node, ch[node]));
  for (__typeof(veled[node].begin()) it = veled[node].begin();
       it != veled[node].end(); it++) {
    int x = *it;
    if (x == root) continue;
    if (mark && ch[node] == x)
      yaz(x, 0);
    else
      f(x);
  }
}
void match(int node) {
  while (!used[node]) used[node] = 1, node = dad[node];
  int root0;
  root0 = root = node;
  rem(root);
  dfs(root);
  pair<int, int> ans = max(dn[root][0], dn[root][1]);
  rem(root);
  root = dad[root];
  dfs(root);
  if (ans < max(dn[root][0], dn[root][1]))
    ans = max(dn[root][0], dn[root][1]);
  else {
    rem(root);
    root = root0;
    dfs(root);
  }
  f(root);
  res = res + ans;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    scanf("%d %d", &dad[i], &s[i]), s[i]--;
    veled[dad[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++)
    if (!used[i]) match(i);
  printf("%d %d\n", (res).first, (res).second);
  ;
  for (__typeof(ansv.begin()) it = ansv.begin(); it != ansv.end(); it++)
    printf("%d %d\n", (*it).first, (*it).second);
  ;
  return 0;
}