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:16777216")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int next239[100000], t[100000];
vector<int> prev239[100000];
int color[100000], was[100000], col[100000];
vector<pair<int, int> > res;
pair<int, int> ans1[100000], ans2[100000];
int next2[100000];
queue<int> q;
void parse(int x) {
  was[x] = 1;
  col[next239[x]]--;
  if (col[next239[x]] == 0) q.push(next239[x]);
}
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);
}
pair<int, int> table[2][100001];
int o[2][100001];
pair<int, int> get(int x, int y) { return make_pair(1, t[x] != t[y]); }
void calc(int x) {
  pair<int, int> sum0 = make_pair(0, 0);
  pair<int, int> sum1 = make_pair(0, 0);
  for (int i = 0; i < (((int)(prev239[x]).size())); i++) {
    int u = prev239[x][i];
    if (was[u] == 0) continue;
    calc(u);
    sum0 = sum0 + ans1[u];
    sum1 = sum1 + ans1[u];
  }
  pair<int, int> a2 = sum1;
  next2[x] = -1;
  for (int i = 0; i < (((int)(prev239[x]).size())); i++) {
    int u = prev239[x][i];
    if (was[u] == 0) continue;
    pair<int, int> tmp = sum1 + ans2[u] - ans1[u] + get(x, u);
    if (tmp > a2) {
      a2 = tmp;
      next2[x] = u;
    }
  }
  ans1[x] = a2;
  ans2[x] = sum0;
}
void add(int x, int f) {
  for (int i = 0; i < (((int)(prev239[x]).size())); i++) {
    int u = prev239[x][i];
    if (was[u] == 0) continue;
    if (u == next2[x] && f == 1) {
      add(u, 0);
      res.push_back(make_pair(x, u));
    } else
      add(u, 1);
  }
}
pair<int, int> getans(int x) {
  vector<int> mas;
  int cur = x;
  do {
    mas.push_back(cur);
    color[cur] = 1;
    cur = next239[cur];
  } while (next239[cur] != x);
  mas.push_back(cur);
  color[cur] = 1;
  int n = ((int)(mas).size());
  for (int i = 0; i < (n); i++) calc(mas[i]);
  mas.push_back(mas[0]);
  for (int l = 0; l < (2); l++) {
    table[l][n] = make_pair(0, 0);
  }
  for (int l = 0; l < (2); l++)
    for (int i = (n)-1; i >= 0; i--) {
      pair<int, int> &ans = table[l][i];
      if (i == n - 1) {
        if (l == 0) {
          ans = get(mas[i], mas[0]) + ans2[mas[i]];
          o[l][i] = 1;
        } else {
          ans = ans1[mas[i]];
          o[l][i] = 0;
        }
      } else {
        if (i == 0 && l == 0) {
          ans = table[l][i + 1] + ans2[mas[0]];
          o[l][i] = 0;
          continue;
        }
        ans = ans1[mas[i]] + table[l][i + 1];
        o[l][i] = 0;
        if (l != 0 || i != n - 2) {
          pair<int, int> tmp = get(mas[i], mas[i + 1]) + ans2[mas[i]] +
                               ans2[mas[i + 1]] + table[l][i + 2];
          if (ans < tmp) {
            ans = tmp;
            o[l][i] = 1;
          }
        }
      }
    }
  int cl = 0;
  if (table[1][0] > table[0][0]) cl = 1;
  int cp = 0;
  while (cp < n) {
    if (o[cl][cp]) {
      res.push_back(make_pair(mas[cp], mas[cp + 1]));
      add(mas[cp], 0);
      if (cp + 1 < n) add(mas[cp + 1], 0);
      cp += 2;
    } else {
      if (cl == 0 && cp == 0)
        add(mas[cp], 0);
      else
        add(mas[cp], 1);
      cp++;
    }
  }
  return max(table[1][0], table[0][0]);
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    col[a]++;
    prev239[a].push_back(i);
    next239[i] = a;
    t[i] = b;
  }
  for (int i = 0; i < (n); i++)
    if (col[i] == 0) q.push(i);
  while (!q.empty()) {
    parse(q.front());
    q.pop();
  }
  pair<int, int> ans = make_pair(0, 0);
  memset(color, -1, sizeof(color));
  for (int i = 0; i < (n); i++)
    if (!was[i] && color[i] == -1) {
      ans = ans + getans(i);
    }
  cout << ans.first << ' ' << ans.second << endl;
  for (int i = 0; i < (((int)(res).size())); i++) {
    cout << res[i].first + 1 << ' ' << res[i].second + 1 << endl;
  }
  return 0;
}