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 = 0x3f3f3f3f, maxn = 100005;
struct P {
  int x, y;
  P(){};
  P(int _x, int _y) { x = _x, y = _y; }
  P operator+(const P& b) const { return P(x + b.x, y + b.y); }
  P operator-(const P& b) const { return P(x - b.x, y - b.y); }
  bool operator<(const P& b) {
    if (x != b.x) return x < b.x;
    return y < b.y;
  }
};
int n, f[maxn], s[maxn], vis[maxn], son[maxn], root;
vector<int> g[maxn];
P dp[maxn][2], ans;
vector<P> vec, temp;
void dfs(int u) {
  dp[u][0] = dp[u][1] = P(0, 0);
  vis[u] = 1, son[u] = 0;
  P res = P(0, 0);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == root) continue;
    dfs(v);
    dp[u][1] = dp[u][1] + dp[v][0];
    P now = P(1, s[u] ^ s[v]) + dp[v][1] - dp[v][0];
    if (res < now) res = now, son[u] = v;
  }
  dp[u][0] = dp[u][1] + res;
}
void path(int u, int sta) {
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == root) continue;
    if (sta == 1)
      path(v, 0);
    else if (son[u] == v)
      temp.push_back(P(u, v)), path(v, 1);
    else
      path(v, 0);
  }
}
void Deal(int u) {
  while (!vis[u]) vis[u] = 1, u = f[u];
  P res = P(0, 0);
  for (int i = 0; i < 2; i++) {
    root = u;
    dfs(root);
    if (res < dp[root][0]) {
      res = dp[root][0];
      temp.clear();
      path(root, 0);
    }
    u = f[u];
  }
  ans = ans + res;
  for (int i = 0; i < temp.size(); i++) vec.push_back(temp[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &f[i], &s[i]);
    s[i]--;
    g[f[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) Deal(i);
  printf("%d %d\n", ans.x, ans.y);
  for (int i = 0; i < vec.size(); i++) printf("%d %d\n", vec[i].x, vec[i].y);
  return 0;
}