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;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret = a;
  ret.first += b.first, ret.second += b.second;
  return ret;
}
pair<int, int> operator-(pair<int, int> b, pair<int, int> a) {
  pair<int, int> ret = b;
  ret.first -= a.first, ret.second -= a.second;
  return ret;
}
pair<int, int> qmax(pair<int, int> a, pair<int, int> b) {
  return (a > b) ? a : b;
}
int n;
int par[100100];
bool is_anc[100100], mx_tp[100100];
vector<int> son[100100];
bool col[100100];
bool done[100100], doing[100100];
bool in_cyc[100100];
int now_rt = -1;
int ntp;
pair<int, int> f[2][100100], g[2][100100];
int lst[2][100100];
void get_dp(int now) {
  done[now] = 1;
  pair<int, int> sum = make_pair(0, 0);
  for (int i = 0; i < (int)son[now].size(); i++) {
    if (par[son[now][i]] == now) {
      get_dp(son[now][i]);
      sum = sum + f[ntp][son[now][i]];
    }
  }
  g[ntp][now] = sum;
  f[ntp][now] = sum;
  lst[ntp][now] = -1;
  for (int i = 0; i < (int)son[now].size(); i++) {
    if (par[son[now][i]] == now) {
      pair<int, int> ret = sum - f[ntp][son[now][i]] + g[ntp][son[now][i]] +
                           make_pair(1, (bool)(col[now] != col[son[now][i]]));
      if (ret > f[ntp][now]) {
        f[ntp][now] = ret;
        lst[ntp][now] = son[now][i];
      }
    }
  }
}
void get_ans(int now, bool tp, bool is_f) {
  if (is_f && lst[tp][now] >= 0) {
    cout << now + 1 << " " << lst[tp][now] + 1 << endl;
  }
  for (int i = 0; i < (int)son[now].size(); i++) {
    if (par[son[now][i]] == now) {
      get_ans(son[now][i], tp, !(is_f && (son[now][i] == lst[tp][now])));
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> par[i];
    par[i]--;
    son[par[i]].push_back(i);
    int ncol;
    cin >> ncol;
    col[i] = (bool)(ncol - 1);
  }
  pair<int, int> ans = make_pair(0, 0);
  for (int curcur = 0; curcur < n; curcur++) {
    if (!done[curcur]) {
      int i = curcur;
      while (!in_cyc[i]) {
        in_cyc[i] = 1;
        i = par[i];
      }
      now_rt = i;
      int pos0 = i, pos1 = par[i];
      int parpos0 = par[pos0], parpos1 = par[pos1];
      ntp = 0;
      par[pos0] = -1;
      get_dp(pos0);
      par[pos0] = parpos0;
      ntp = 1;
      par[pos1] = -1;
      get_dp(pos1);
      par[pos1] = parpos1;
      if (f[0][pos0] > f[1][pos1])
        ans = ans + f[0][pos0], is_anc[pos0] = 1, mx_tp[pos0] = 0;
      else
        ans = ans + f[1][pos1], is_anc[pos1] = 1, mx_tp[pos1] = 1;
    }
  }
  cout << ans.first << " " << ans.second << endl;
  for (int i = 0; i < n; i++) {
    if (is_anc[i]) {
      par[i] = -1;
      get_ans(i, mx_tp[i], 1);
    }
  }
  return 0;
}