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;
int n;
int sex[100010];
vector<pair<int, int> > v[100010];
bool vis[100010], we[100010];
pair<int, int> d[100010][3];
int cor[100010];
deque<int> dc;
map<pair<int, int>, vector<int> > mp;
int sb = -1, se = -1, dl;
pair<int, int> res = make_pair(0, 0), allr = make_pair(0, 0);
vector<pair<int, int> > vri, vt, vr;
vector<int> nod;
pair<int, int> operator+(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
pair<int, int> operator-(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first - y.first, x.second - y.second);
}
void dfsnod(int x, int y) {
  we[x] = 1, nod.push_back(x);
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].second == y) continue;
    int xi = v[x][i].first;
    if (!we[xi]) dfsnod(xi, v[x][i].second);
  }
}
void dfscir(int x, int y) {
  if (sb != -1) return;
  vis[x] = 1;
  dc.push_back(x);
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].second == y) continue;
    int xi = v[x][i].first;
    if (!vis[xi])
      dfscir(xi, v[x][i].second);
    else {
      sb = xi, se = x;
      return;
    }
    if (sb != -1) return;
  }
  dc.pop_back();
}
void dfs(int x, int y) {
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].second == dl || v[x][i].second == y) continue;
    int xi = v[x][i].first;
    dfs(xi, v[x][i].second);
    d[x][0] = d[x][0] + d[xi][2];
  }
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i].second == dl || v[x][i].second == y) continue;
    int xi = v[x][i].first;
    pair<int, int> p = d[x][0] - d[xi][2] + d[xi][0];
    p.first++;
    if (sex[x] != sex[xi]) p.second++;
    d[x][1] = max(d[x][1], p);
  }
  d[x][2] = max(d[x][0], d[x][1]);
  cor[x] = (d[x][2] == d[x][0] ? 0 : 1);
}
void chas(int x, int z, int y) {
  if (!y) {
    for (int i = 0; i < v[x].size(); i++) {
      if (v[x][i].second == dl || v[x][i].second == z) continue;
      int xi = v[x][i].first;
      chas(xi, v[x][i].second, cor[xi]);
    }
  } else {
    int ct = -1;
    for (int i = 0; i < v[x].size(); i++) {
      int xi = v[x][i].first;
      if (v[x][i].second == dl || v[x][i].second == z) continue;
      pair<int, int> p = d[x][0] - d[xi][2] + d[xi][0];
      p.first++;
      if (sex[x] != sex[xi]) p.second++;
      if (d[x][1] == p) {
        vt.push_back(make_pair(x, xi));
        chas(xi, v[x][i].second, 0);
        ct = xi;
        break;
      }
    }
    for (int i = 0; i < v[x].size(); i++) {
      if (v[x][i].second == dl || v[x][i].second == z) continue;
      int xi = v[x][i].first;
      if (xi != ct) chas(xi, v[x][i].second, cor[xi]);
    }
  }
}
pair<int, int> del(int x, int rt) {
  dl = x;
  for (int i = 0; i < nod.size(); i++)
    d[nod[i]][0] = d[nod[i]][1] = d[nod[i]][2] = make_pair(0, 0);
  dfs(rt, -1);
  vt.clear();
  if (d[rt][0] > d[rt][1]) {
    chas(rt, -1, 0);
    return d[rt][0];
  } else {
    chas(rt, -1, 1);
    return d[rt][1];
  }
}
void work(int rt) {
  dc.clear(), nod.clear();
  sb = se = -1, res = make_pair(0, 0);
  dfsnod(rt, -1);
  dfscir(rt, -1);
  while (dc.front() != sb) dc.pop_front();
  for (int i = 0; i < 2; i++) {
    int x = dc[i], y = dc[(i + 1) % (int)(dc.size())];
    pair<int, int> pt = del(mp[make_pair(min(x, y), max(x, y))].back(), rt);
    if (res < pt) res = pt, vri = vt;
    mp[make_pair(min(x, y), max(x, y))].pop_back();
  }
  allr = allr + res;
  for (int i = 0; i < vri.size(); i++) vr.push_back(vri[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d%d", &x, &sex[i]);
    x--;
    v[i].push_back(make_pair(x, i));
    v[x].push_back(make_pair(i, i));
    mp[make_pair(min(x, i), max(x, i))].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    if (we[i]) continue;
    work(i);
  }
  printf("%d %d\n", allr.first, allr.second);
  for (int i = 0; i < vr.size(); i++)
    printf("%d %d\n", vr[i].first + 1, vr[i].second + 1);
  return 0;
}