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;
inline int powmod(int a, int b) {
  int tmp = 1;
  for (; b; b >>= 1) {
    if (b & 1) tmp = tmp * a;
    a = a * a;
  }
  return tmp;
}
template <class T>
inline void R(T &xx) {
  xx = 0;
  char ch = getchar();
  bool F = 0;
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') F = 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();
  if (F) xx = -xx;
}
inline 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);
}
inline 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);
}
int n, BG, H[100011], nxt[100011], c[100011], fa[100011], g[100011];
pair<int, int> f[100011][2], An[100011], q[100011], ans;
int len, ss;
bool vis[100011];
void dp(int u) {
  vis[u] = 1, f[u][0] = f[u][1] = make_pair(0, 0), g[u] = 0;
  pair<int, int> mx(0, 0), t;
  for (int v = H[u]; v; v = nxt[v])
    if (v != BG) {
      dp(v), f[u][0] = f[u][0] + f[v][1];
      t = f[v][0] - f[v][1] + make_pair(1, c[u] != c[v]);
      if (t > mx) mx = t, g[u] = v;
    }
  f[u][1] = f[u][0] + mx;
}
void get(int u, int t) {
  for (int v = H[u]; v; v = nxt[v])
    if (v != BG)
      if (t && v == g[u])
        q[ss++] = make_pair(u, v), get(v, 0);
      else
        get(v, 1);
}
void work(int u) {
  for (; !vis[u]; u = fa[u]) vis[u] = 1;
  pair<int, int> res(0, 0);
  for (int i = 0; i < (int)(2); i++) {
    BG = u, dp(u);
    if (f[u][1] > res) res = f[u][1], ss = 0, get(u, 1);
    u = fa[u];
  }
  ans = ans + res;
  for (int i = 0; i < (int)(ss); i++) An[len++] = q[i];
}
int main() {
  R(n);
  for (int i = (1); i <= (n); i++)
    R(fa[i]), R(c[i]), nxt[i] = H[fa[i]], H[fa[i]] = i;
  for (int i = (1); i <= (n); i++)
    if (!vis[i]) work(i);
  printf("%d %d\n", ans.first, ans.second);
  for (int i = 0; i < (int)(len); i++)
    printf("%d %d\n", An[i].first, An[i].second);
  return 0;
}