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 = 100010;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
int n, fr[MAXN], sex[MAXN], kiedyje[MAXN], a, b, ak;
vector<int> graf[MAXN];
bool je[MAXN], blok[MAXN];
pair<int, int> aa, bb, res, ak_cykl_res, dp[MAXN][2];
pair<int, int> tmp;
vector<pair<int, int> > pary, pary1, pary2;
pair<int, int> fun(int a, int b) {
  if (sex[a] == sex[b]) return make_pair(1, 0);
  return make_pair(1, 1);
}
void dfs(int v) {
  for (int i = 0; i < graf[v].size(); i++)
    if (!blok[graf[v][i]]) dfs(graf[v][i]);
  dp[v][0] = dp[v][1] = make_pair(0, 0);
  pair<int, int> sum = make_pair(0, 0);
  for (int i = 0; i < graf[v].size(); i++)
    if (!blok[graf[v][i]]) {
      dp[v][0] = dp[v][0] + max(dp[graf[v][i]][0], dp[graf[v][i]][1]);
      sum = sum + max(dp[graf[v][i]][0], dp[graf[v][i]][1]);
    }
  for (int i = 0; i < graf[v].size(); i++)
    if (!blok[graf[v][i]]) {
      dp[v][1] = max(dp[v][1], sum - max(dp[graf[v][i]][0], dp[graf[v][i]][1]) +
                                   dp[graf[v][i]][0] + fun(v, graf[v][i]));
    }
}
void regen(int v, int st, vector<pair<int, int> > &pary) {
  if (st == 0) {
    for (int i = 0; i < graf[v].size(); i++)
      if (!blok[graf[v][i]])
        if (dp[graf[v][i]][0] > dp[graf[v][i]][1])
          regen(graf[v][i], 0, pary);
        else
          regen(graf[v][i], 1, pary);
  } else {
    pair<int, int> sum = make_pair(0, 0);
    for (int i = 0; i < graf[v].size(); i++)
      if (!blok[graf[v][i]])
        sum = sum + max(dp[graf[v][i]][0], dp[graf[v][i]][1]);
    for (int i = 0; i < graf[v].size(); i++)
      if (!blok[graf[v][i]] && sum - max(dp[graf[v][i]][0], dp[graf[v][i]][1]) +
                                       dp[graf[v][i]][0] + fun(v, graf[v][i]) ==
                                   dp[v][1]) {
        pary.push_back(make_pair(v, graf[v][i]));
        regen(graf[v][i], 0, pary);
        for (int j = 0; j < graf[v].size(); j++)
          if (!blok[graf[v][j]] && j != i)
            if (dp[graf[v][j]][0] > dp[graf[v][j]][1])
              regen(graf[v][j], 0, pary);
            else
              regen(graf[v][j], 1, pary);
        return;
      }
  }
}
pair<int, int> licz_res_bez(int a, vector<pair<int, int> > &pary) {
  dfs(a);
  regen(a, 0, pary);
  return dp[a][0];
}
pair<int, int> licz_res_naj(int a, vector<pair<int, int> > &pary) {
  dfs(a);
  if (dp[a][0] > dp[a][1])
    regen(a, 0, pary);
  else
    regen(a, 1, pary);
  return max(dp[a][0], dp[a][1]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> fr[i] >> sex[i];
    graf[fr[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (!je[i]) {
      ak = i;
      je[ak] = true;
      kiedyje[ak] = i;
      while (!je[fr[ak]]) {
        je[fr[ak]] = true;
        kiedyje[fr[ak]] = i;
        ak = fr[ak];
      }
      if (kiedyje[fr[ak]] != i) continue;
      a = ak;
      b = fr[ak];
      pary1.clear();
      pary2.clear();
      blok[b] = true;
      blok[a] = true;
      aa = licz_res_bez(a, pary1);
      bb = licz_res_bez(b, pary1);
      ak_cykl_res = aa + bb + fun(a, b);
      pary1.push_back(make_pair(a, b));
      blok[b] = false;
      blok[a] = false;
      for (int j = 0; j < graf[b].size(); j++)
        if (graf[b][j] == a) {
          swap(graf[b][j], graf[b][graf[b].size() - 1]);
          graf[b].pop_back();
        }
      tmp = licz_res_naj(a, pary2);
      if (ak_cykl_res < tmp) {
        ak_cykl_res = tmp;
        pary1 = pary2;
      }
      for (int i = 0; i < pary1.size(); i++) pary.push_back(pary1[i]);
      res = res + ak_cykl_res;
    }
  cout << res.first << " " << res.second << endl;
  for (int i = 0; i < pary.size(); i++)
    cout << pary[i].first << " " << pary[i].second << endl;
}