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 INF = 1e9 + 7;
struct node {
  int cnt, bg, cu, cv;
  vector<node*> from;
  node(int tot = 0, int ds = 0, int u = 0, int v = 0) {
    cnt = tot;
    bg = ds;
    cu = u;
    cv = v;
  }
};
typedef node* state;
state add(const state& a, const state& b) {
  state ans = new node(a->cnt + b->cnt, a->bg + b->bg);
  ans->from.push_back(a);
  ans->from.push_back(b);
  return ans;
}
state maxs(const state& a, const state& b) {
  node cur;
  if (a->cnt != b->cnt)
    cur = a->cnt > b->cnt ? *a : *b;
  else
    cur = a->bg > b->bg ? *a : *b;
  return new node(cur);
}
void output(const state& v) {
  if (v->cu && v->cv) printf("%d %d\n", v->cu, v->cv);
  for (int k = 0; k < (v->from.size()); k++) output(v->from[k]);
}
vector<int> G[100005];
int col[100005];
vector<int> vec;
int vis[100005];
state dpt[100005][2];
state dpl[100005];
int rt;
void dfs1(int v, int par) {
  bool hf = false;
  if (rt == -1) {
    vis[v] = 1;
    vec.push_back(v);
  } else
    vis[v] = -1;
  for (int k = 0; k < (G[v].size()); k++) {
    int u = G[v][k];
    if (!vis[u])
      dfs1(u, v);
    else if (rt == -1 && vis[u] == 1) {
      if (u == par && !hf)
        hf = true;
      else
        rt = u;
    }
  }
  if (rt == -1) {
    vis[v] = -1;
    vec.pop_back();
  }
}
void dfs2(int v, int par) {
  dpt[v][0] = new node();
  vector<state> cv;
  state cur = new node();
  for (int k = 0; k < (G[v].size()); k++) {
    int u = G[v][k];
    if (u == par || vis[u] == 1) continue;
    dfs2(u, v);
    cv.push_back(dpt[v][0]);
    dpt[v][0] = add(dpt[v][0], dpt[u][1]);
  }
  dpt[v][1] = new node(*dpt[v][0]);
  for (int k = G[v].size() - 1; k >= 0; k--) {
    int u = G[v][k];
    if (u == par || vis[u] == 1) continue;
    dpt[v][1] = maxs(dpt[v][1], add(add(add(cv.back(), cur), dpt[u][0]),
                                    new node(1, col[u] != col[v], u, v)));
    cv.pop_back();
    cur = add(cur, dpt[u][1]);
  }
}
state solve(const vector<int>& vec) {
  for (int k = 0; k <= vec.size(); k++) dpl[k] = new node();
  for (int k = 0; k < (vec.size()); k++) {
    dpl[k + 1] = maxs(dpl[k + 1], add(dpl[k], dpt[vec[k]][1]));
    if (k + 1 < vec.size())
      dpl[k + 2] = maxs(
          dpl[k + 2],
          add(add(dpl[k], add(dpt[vec[k]][0], dpt[vec[k + 1]][0])),
              new node(1, col[vec[k]] != col[vec[k + 1]], vec[k], vec[k + 1])));
  }
  return dpl[vec.size()];
}
state solve(int v) {
  if (vis[v]) return new node();
  rt = -1;
  vec.clear();
  dfs1(v, -1);
  for (int k = 0; k < (vec.size()); k++)
    if (vec[k] == rt) {
      vec.erase(vec.begin(), vec.begin() + k);
      break;
    } else
      vis[vec[k]] = -1;
  for (int k = 0; k < (vec.size()); k++) dfs2(vec[k], -1);
  state a1 = solve(vec);
  state a2 =
      new node(1, col[vec.front()] != col[vec.back()], vec.front(), vec.back());
  a2 = add(a2, add(dpt[vec.front()][0], dpt[vec.back()][0]));
  vec.pop_back();
  vec.erase(vec.begin());
  a2 = add(a2, solve(vec));
  return maxs(a1, a2);
}
int main() {
  int n, v;
  scanf("%d", &n);
  for (int k = 1; k <= (n); k++) {
    scanf("%d%d", &v, &col[k]);
    G[v].push_back(k);
    G[k].push_back(v);
  }
  state ans = new node();
  for (int k = 1; k <= (n); k++) ans = add(ans, solve(k));
  printf("%d %d\n", ans->cnt, ans->bg);
  output(ans);
  return 0;
}