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 N = 1e5 + 5;
int n, f[N], s[N];
vector<int> e[N];
pair<int, int> dp[N][2];
int pre[N][2];
bool mark[N];
pair<int, int> mx;
vector<pair<int, int> > ans;
pair<int, int> operator+(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
pair<int, int> operator-(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first - y.first, x.second - y.second);
}
void dfs(int root, int now) {
  mark[now] = true;
  for (auto u : e[now])
    if (u != root) dfs(root, u);
  pair<int, int> sum = make_pair(0, 0);
  dp[now][0] = dp[now][1] = make_pair(0, 0);
  pre[now][1] = -1;
  for (auto u : e[now])
    if (u != root) sum = sum + max(dp[u][0], dp[u][1]);
  dp[now][0] = sum;
  for (auto u : e[now])
    if (u != root) {
      pair<int, int> tmp = sum - max(dp[u][0], dp[u][1]) + dp[u][0];
      tmp.first++, tmp.second += s[now] ^ s[u];
      if (tmp > dp[now][1]) {
        dp[now][1] = tmp;
        pre[now][1] = u;
      }
    }
}
void getans(int root, int now, int op, vector<pair<int, int> >& w) {
  if (op == 1) {
    w.push_back(make_pair(now, pre[now][1]));
    for (auto u : e[now])
      if (u != root) {
        if (u == pre[now][1])
          getans(root, u, 0, w);
        else {
          if (dp[u][1] > dp[u][0])
            getans(root, u, 1, w);
          else
            getans(root, u, 0, w);
        }
      }
  } else {
    for (auto u : e[now])
      if (u != root) {
        if (dp[u][1] > dp[u][0])
          getans(root, u, 1, w);
        else
          getans(root, u, 0, w);
      }
  }
}
void solve(int now) {
  while (!mark[now]) {
    mark[now] = true;
    now = f[now];
  }
  vector<pair<int, int> > ver;
  pair<int, int> best = make_pair(0, 0);
  for (int i = 0; i < (int)(2); ++i) {
    dfs(now, now);
    pair<int, int> tmp = max(dp[now][0], dp[now][1]);
    if (tmp > best) {
      best = tmp;
      ver.clear();
      if (dp[now][1] > dp[now][0])
        getans(now, now, 1, ver);
      else
        getans(now, now, 0, ver);
    }
    now = f[now];
  }
  mx = mx + best;
  ans.insert(ans.end(), ver.begin(), ver.end());
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%d%d", &f[i], &s[i]);
    f[i]--, s[i]--;
    e[f[i]].push_back(i);
  }
  for (int i = 0; i < (int)(n); ++i)
    if (!mark[i]) solve(i);
  printf("%d %d\n", mx.first, mx.second);
  for (auto i : ans) printf("%d %d\n", i.first + 1, i.second + 1);
  return 0;
}