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 void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, x, y, typ[200005], hd[200005], nxt[200005], to[200005],
    g[200005], vis[200005], bst[2][200005], incir[200005], mxs, ban;
pair<int, int> dp[2][200005][2], mx, ans;
vector<pair<int, int> > res;
pair<int, int> operator+(const pair<int, int> &x, const pair<int, int> &y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
pair<int, int> operator-(const pair<int, int> &x, const pair<int, int> &y) {
  return make_pair(x.first - y.first, x.second - y.second);
}
void dfs(int x, int fa, int t) {
  vis[x] = 1;
  dp[t][x][0] = dp[t][x][1] = make_pair(0, 0);
  int i;
  for (i = hd[x]; i; i = nxt[i])
    if (to[i] != fa && i / 2 != ban / 2) {
      dfs(to[i], x, t);
      dp[t][x][0] = dp[t][x][0] + max(dp[t][to[i]][0], dp[t][to[i]][1]);
    }
  dp[t][x][1] = dp[t][x][0];
  bst[t][x] = 0;
  for (i = hd[x]; i; i = nxt[i])
    if (to[i] != fa && i / 2 != ban / 2) {
      pair<int, int> s = dp[t][x][0] + dp[t][to[i]][0] -
                         max(dp[t][to[i]][0], dp[t][to[i]][1]) +
                         make_pair(1, typ[x] != typ[to[i]]);
      if (s > dp[t][x][1]) {
        dp[t][x][1] = s;
        bst[t][x] = to[i];
      }
    }
}
void print(int t, int x, int fa, int y) {
  if (!y || !bst[t][x]) {
    int i;
    for (i = hd[x]; i; i = nxt[i])
      if (to[i] != fa && i / 2 != ban / 2) {
        print(t, to[i], x, 1);
      }
  } else {
    int i;
    for (i = hd[x]; i; i = nxt[i])
      if (to[i] != fa && i / 2 != ban / 2) {
        if (bst[t][x] == to[i]) {
          res.push_back(make_pair(x, to[i]));
          print(t, to[i], x, 0);
        } else
          print(t, to[i], x, 1);
      }
  }
}
void solve(int x) {
  while (!vis[x]) {
    vis[x] = 1;
    x = g[x];
  }
  while (vis[x] == 1) {
    vis[x] = 2;
    incir[x] = 1;
    x = g[x];
  }
  vector<int> t;
  int i;
  for (i = hd[x]; i; i = nxt[i])
    if (incir[to[i]]) {
      t.push_back(i);
    }
  mx = make_pair(0, 0);
  for (i = 0; i < t.size(); i++) {
    ban = t[i];
    dfs(x, 0, i);
    if (max(dp[i][x][0], dp[i][x][1]) > mx) {
      mx = max(dp[i][x][0], dp[i][x][1]);
      mxs = i;
    }
  }
  ans = ans + mx;
  ban = t[mxs];
  print(mxs, x, 0, 1);
}
int main() {
  read(n);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    read(g[i]);
    read(typ[i]);
    nxt[i * 2 + 1] = hd[i];
    hd[i] = i * 2 + 1;
    to[i * 2 + 1] = g[i];
    nxt[i * 2] = hd[g[i]];
    hd[g[i]] = i * 2;
    to[i * 2] = i;
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    if (!vis[i]) {
      solve(i);
    }
  }
  printf("%d %d\n", ans.first, ans.second);
  for (__typeof((res).begin()) it = (res).begin(); it != (res).end(); it++) {
    printf("%d %d\n", it->first, it->second);
  }
  return 0;
}