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+(const pair<int, int>& a, const pair<int, int>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator*(const int& a, const pair<int, int>& b) {
  return make_pair(a * b.first, a * b.second);
}
vector<int> sex, parent, used[2], path, bestw[2];
vector<int> was, points;
vector<vector<int> > adj;
vector<pair<int, int> > w[2], o[2];
int k, mark, n;
void dfs(int v, int color) {
  if (was[v]) {
    if (was[v] == color) points.push_back(v);
    return;
  }
  was[v] = color;
  for (int i = 0; i < adj[v].size(); ++i) dfs(adj[v][i], color);
}
void go(int v) {
  if (used[k][v]) return;
  used[k][v] = 1;
  w[k][v] = o[k][v] = make_pair(0, 0);
  for (int i = 0; i < adj[v].size(); ++i) {
    int to = adj[v][i];
    go(to);
    if (mark != to) o[k][v] = o[k][v] + max(w[k][to], o[k][to]);
  }
  for (int i = 0; i < adj[v].size(); ++i) {
    int to = adj[v][i];
    if (to == mark) continue;
    pair<int, int> val = o[k][v] + (-1) * max(w[k][to], o[k][to]) + o[k][to] +
                         make_pair(1, sex[v] != sex[to]);
    if (w[k][v] < val) {
      bestw[k][v] = to;
      w[k][v] = val;
    }
  }
}
void make_path(int v, bool with) {
  int to = -1;
  if (with) {
    to = bestw[k][v];
    path[to] = 1;
  }
  for (int i = 0; i < adj[v].size(); ++i) {
    int to2 = adj[v][i];
    if (to2 != mark) make_path(to2, (to2 != to) && (w[k][to2] > o[k][to2]));
  }
}
int main() {
  cin >> n;
  adj.resize(n);
  sex.resize(n);
  path.resize(n, 0);
  parent.resize(n);
  was.resize(n, 0);
  for (int i = 0; i < 2; ++i) {
    bestw[i].resize(n, -1);
    w[i].resize(n);
    o[i].resize(n);
    used[i].resize(n, 0);
  }
  for (int i = 0; i < n; ++i) {
    int f, s;
    cin >> f >> s;
    f--, s--;
    parent[i] = f;
    sex[i] = s;
    adj[f].push_back(i);
  }
  for (int i = 0; i < n; ++i)
    if (!was[i]) dfs(i, i + 1);
  for (int i = 0; i < points.size(); ++i) {
    int vv[2] = {points[i], parent[points[i]]};
    for (int p = 0; p < 2; ++p) {
      k = p;
      mark = vv[p];
      go(vv[p]);
    }
    int v;
    k = max(o[0][vv[0]], w[0][vv[0]]) <= max(o[1][vv[1]], w[1][vv[1]]);
    v = mark = vv[k];
    make_path(v, w[k][v] > o[k][v]);
  }
  int all = 0, diff = 0;
  for (int i = 0; i < n; ++i)
    if (path[i]) {
      all++;
      diff += (sex[i] != sex[parent[i]]);
    }
  cout << all << " " << diff << endl;
  for (int i = 0; i < n; ++i)
    if (path[i]) cout << i + 1 << " " << parent[i] + 1 << endl;
  return 0;
}