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>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Inf = 1000000000;
const int Maxn = 100005;
int n;
int f[Maxn], s[Maxn];
vector<int> neigh[Maxn];
bool taken[Maxn];
vector<int> comp;
int root, mid;
pair<int, int> edge;
pair<int, int> dp[Maxn][2];
int from[Maxn];
pair<int, int> res = pair<int, int>(0, 0);
vector<pair<int, int> > rpairs;
pair<int, int> Max(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first > b.first ? a : b;
  return a.second > b.second ? a : b;
}
pair<int, int> Add(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
pair<int, int> Sub(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first - b.first, a.second - b.second);
}
void getComp(int v) {
  comp.push_back(v);
  taken[v] = true;
  while (!taken[f[v]]) {
    v = f[v];
    comp.push_back(v);
    taken[v] = true;
  }
  root = v;
  mid = f[v];
  edge = pair<int, int>(1, s[root] != s[mid]);
  for (int i = 0; i < comp.size(); i++) {
    int v = comp[i];
    for (int j = 0; j < neigh[v].size(); j++) {
      int u = neigh[v][j];
      if (!taken[u]) {
        comp.push_back(u);
        taken[u] = true;
      }
    }
  }
}
void Calc(int v) {
  taken[v] = true;
  dp[v][0] = dp[v][1] = pair<int, int>(0, 0);
  pair<int, int> mx = pair<int, int>(-Inf, -Inf);
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (taken[u]) continue;
    Calc(u);
    dp[v][0] = Add(dp[v][0], Max(dp[u][0], dp[u][1]));
    mx = Max(mx, Add(pair<int, int>(1, s[v] != s[u]),
                     Sub(dp[u][0], Max(dp[u][0], dp[u][1]))));
  }
  dp[v][1] = Add(dp[v][0], mx);
}
void Get(int v, int f) {
  taken[v] = true;
  int spec;
  if (f == 0)
    spec = -1;
  else {
    for (int i = 0; i < neigh[v].size(); i++) {
      int u = neigh[v][i];
      if (taken[u]) continue;
      if (Sub(dp[v][1], dp[v][0]) ==
          Add(pair<int, int>(1, s[v] != s[u]),
              Sub(dp[u][0], Max(dp[u][0], dp[u][1])))) {
        spec = u;
        break;
      }
    }
    rpairs.push_back(pair<int, int>(v, spec));
  }
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (taken[u]) continue;
    if (spec == u)
      Get(u, 0);
    else if (Max(dp[u][0], dp[u][1]) != dp[u][0])
      Get(u, 1);
    else
      Get(u, 0);
  }
}
void Process(int i) {
  comp.clear();
  getComp(i);
  for (int i = 0; i < comp.size(); i++) taken[comp[i]] = false;
  Calc(root);
  pair<int, int> a = Max(dp[root][0], dp[root][1]);
  for (int i = 0; i < comp.size(); i++) taken[comp[i]] = false;
  taken[root] = taken[mid] = true;
  Calc(root);
  Calc(mid);
  pair<int, int> b = Add(edge, Add(dp[root][0], dp[mid][0]));
  if (Max(a, b) != b) {
    for (int i = 0; i < comp.size(); i++) taken[comp[i]] = false;
    Calc(root);
    for (int i = 0; i < comp.size(); i++) taken[comp[i]] = false;
    if (Max(dp[root][0], dp[root][1]) != dp[root][0])
      Get(root, 1);
    else
      Get(root, 0);
  } else {
    for (int i = 0; i < comp.size(); i++) taken[comp[i]] = false;
    taken[root] = taken[mid] = true;
    rpairs.push_back(pair<int, int>(root, mid));
    Get(root, 0);
    Get(mid, 0);
  }
  res = Add(res, Max(a, b));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &f[i], &s[i]);
    neigh[f[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (neigh[i].empty() && !taken[i]) Process(i);
  for (int i = 1; i <= n; i++)
    if (!taken[i]) Process(i);
  printf("%d %d\n", res.first, res.second);
  for (int i = 0; i < rpairs.size(); i++)
    printf("%d %d\n", rpairs[i].first, rpairs[i].second);
  return 0;
}