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;
ifstream in("pairs.in");
ofstream out("pairs.out");
const int DIM = 1e5 + 5;
int nxt[DIM], val[DIM], pos[DIM];
pair<int, int> tdp[DIM][2], cdp[DIM], arr[2][DIM];
deque<int> chn;
bitset<DIM> oki, mrk, ist;
vector<pair<int, int>> sol;
vector<int> edg[DIM];
pair<int, int> operator+(const pair<int, int> &p1, const pair<int, int> &p2) {
  return pair<int, int>(p1.first + p2.first, p1.second + p2.second);
}
pair<int, int> operator-(const pair<int, int> &p1, const pair<int, int> &p2) {
  return pair<int, int>(p1.first - p2.first, p1.second - p2.second);
}
void calcdp(int x) {
  mrk[x] = true;
  pos[x] = 0;
  tdp[x][0] = tdp[x][1] = pair<int, int>(0, 0);
  for (int y : edg[x]) {
    calcdp(y);
    tdp[x][0] = tdp[x][0] + max(tdp[y][0], tdp[y][1]);
    pair<int, int> aux = tdp[y][0] - max(tdp[y][0], tdp[y][1]) +
                         pair<int, int>(1, val[x] != val[y]);
    if (tdp[x][1] < aux) tdp[x][1] = aux, pos[x] = y;
  }
  tdp[x][1] = tdp[x][1] + tdp[x][0];
}
int _nr[2];
void solvedp(int x, bool ok, int nr) {
  if (ok and pos[x]) arr[nr][++_nr[nr]] = make_pair(x, pos[x]);
  for (int y : edg[x]) solvedp(y, (ok and y == pos[x]) ? false : true, nr);
}
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &nxt[i], &val[i]);
    edg[nxt[i]].push_back(i);
  }
  pair<int, int> ans;
  for (int i = 1; i <= n; ++i)
    if (!mrk[i]) {
      chn.clear();
      for (int x = i; true; x = nxt[x]) {
        chn.push_back(x);
        if (!oki[x])
          oki[x] = true;
        else {
          while (chn.front() != chn.back())
            oki[chn.front()] = false, chn.pop_front();
          break;
        }
      }
      pair<int, int> pr1, pr2;
      edg[chn[1]].erase(find(edg[chn[1]].begin(), edg[chn[1]].end(), chn[0]));
      calcdp(chn[0]);
      _nr[0] = 0;
      solvedp(chn[0], true, 0);
      edg[chn[1]].push_back(chn[0]);
      pr1 = max(tdp[chn[0]][0], tdp[chn[0]][1]);
      edg[chn[2]].erase(find(edg[chn[2]].begin(), edg[chn[2]].end(), chn[1]));
      calcdp(chn[1]);
      _nr[1] = 0;
      solvedp(chn[1], true, 1);
      edg[chn[2]].push_back(chn[1]);
      pr2 = max(tdp[chn[1]][0], tdp[chn[1]][1]);
      if (pr1 > pr2) {
        ans = ans + pr1;
        for (int i = 1; i <= pr1.first; ++i) sol.push_back(arr[0][i]);
      } else {
        ans = ans + pr2;
        for (int i = 1; i <= pr2.first; ++i) sol.push_back(arr[1][i]);
      }
    }
  printf("%d %d\n", ans.first, ans.second);
  for (pair<int, int> pr : sol) printf("%d %d\n", pr.first, pr.second);
  return 0;
}