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 GCC optimize("Ofast")
using namespace std;
long long n;
bool vis[100005], pt[2][100005][2];
bool f[100005], tf;
long long p[2][100005][2];
vector<long long> v[100005];
bool to[100005];
pair<long long, long long> dp[2][100005][2];
vector<long long> lst, loop;
vector<pair<long long, long long> > ans;
pair<long long, long long> ansp;
void dfs(long long x, long long fa) {
  if (vis[x] == 1 && tf) {
    bool ff = 0;
    for (auto u : lst) {
      if (u == x) {
        ff = 1;
      }
      if (ff && !to[u]) loop.emplace_back(u), to[u] = 1;
    }
    tf = 0;
    return;
  }
  if (vis[x] == 1) return;
  vis[x] = 1;
  bool ttf = 1;
  for (auto u : v[x]) {
    if (u != fa || !ttf) {
      lst.emplace_back(u);
      dfs(u, x);
      lst.pop_back();
    } else if (u == fa)
      ttf = 0;
  }
}
void get(long long x, long long fa, long long full, long long col) {
  if (pt[col][x][full]) return;
  pt[col][x][full] = 1;
  pair<long long, long long> now;
  for (auto u : v[x])
    if (u != fa) {
      get(u, x, 0, col);
      get(u, x, 1, col);
      now.first += dp[col][u][1].first;
      now.second += dp[col][u][1].second;
    }
  pair<long long, long long> tw = now;
  if (full) {
    for (auto u : v[x])
      if (u != fa) {
        pair<long long, long long> tn =
            make_pair(now.first - dp[col][u][1].first + dp[col][u][0].first + 1,
                      now.second - dp[col][u][1].second + dp[col][u][0].second +
                          (f[x] != f[u]));
        if (tn > tw) {
          tw = tn;
          p[col][x][full] = u;
        }
      }
  }
  dp[col][x][full] = tw;
}
void erase(long long x, long long y) {
  vector<long long> tv;
  bool ttf = 1;
  for (auto u : v[x]) {
    if (u != y || !ttf)
      tv.emplace_back(u);
    else
      ttf = 0;
  }
  v[x] = tv;
}
void into(long long x, long long full, long long col, long long fa) {
  if (p[col][x][full]) {
    ans.emplace_back(make_pair(p[col][x][full], x));
    for (auto u : v[x])
      if (u != fa) {
        if (u == p[col][x][full]) {
          into(u, 0, col, x);
        } else
          into(u, 1, col, x);
      }
  } else {
    for (auto u : v[x])
      if (u != fa) {
        into(u, 1, col, x);
      }
  }
}
void solve(long long x) {
  lst.clear();
  lst.emplace_back(x);
  loop.clear();
  tf = 1;
  dfs(x, -1);
  long long t = loop.back();
  long long cnt = 0;
  long long p1 = 0, p2 = 0;
  for (auto u : v[t]) {
    if (to[u]) {
      cnt++;
      if (cnt == 1)
        p1 = u;
      else if (cnt == 2) {
        p2 = u;
        break;
      }
    }
  }
  erase(p1, t);
  erase(t, p1);
  get(t, -1, 1, 0);
  v[t].emplace_back(p1);
  v[p1].emplace_back(t);
  erase(p2, t);
  erase(t, p2);
  get(t, -1, 1, 1);
  v[t].emplace_back(p2);
  v[p2].emplace_back(t);
  if (dp[0][t][1] > dp[1][t][1]) {
    ansp.first += dp[0][t][1].first;
    ansp.second += dp[0][t][1].second;
    erase(p1, t);
    erase(t, p1);
    into(t, 1, 0, -1);
  } else {
    ansp.first += dp[1][t][1].first;
    ansp.second += dp[1][t][1].second;
    erase(p2, t);
    erase(t, p2);
    into(t, 1, 1, -1);
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long x, y;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;
    if (y == 1) {
      f[i] = 1;
    } else
      f[i] = 0;
    v[i].emplace_back(x);
    v[x].emplace_back(i);
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      solve(i);
    }
  }
  cout << ansp.first << ' ' << ansp.second << '\n';
  for (auto u : ans) cout << u.first << ' ' << u.second << '\n';
  return 0;
}