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 Len = 2333333;
char buf[Len], *p1 = buf, *p2 = buf, duf[Len], *q1 = duf;
inline char gc();
inline int rd();
inline void pc(char c);
inline void rt(int x);
inline void flush();
int n, cnt, r, h[100005], id[100005], f[100005], s[100005], vis[100005],
    g[100005];
pair<int, int> ans, dp[100005][2];
vector<pair<int, int> > V, A;
struct E {
  int to, nxt;
} e[100005];
inline pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
inline pair<int, int> operator-(pair<int, int> a, pair<int, int> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
inline void Add(int u, int v) { e[++cnt] = (E){v, h[u]}, h[u] = cnt; }
void Dfs(int u) {
  vis[u] = 1, g[u] = 0, dp[u][0] = dp[u][1] = make_pair(0, 0);
  for (register int i = h[u]; i; i = e[i].nxt)
    if (i != r) {
      int v = e[i].to;
      Dfs(v), dp[u][1] = dp[u][1] + dp[v][0];
      pair<int, int> t = dp[v][1] - dp[v][0] + make_pair(1, s[u] ^ s[v]);
      if (dp[u][0] < t) dp[u][0] = t, g[u] = v;
    }
  dp[u][0] = dp[u][0] + dp[u][1];
}
void Get(int u, int o) {
  for (register int i = h[u]; i; i = e[i].nxt)
    if (i != r) {
      int v = e[i].to;
      if (!o && g[u] == v)
        V.push_back(make_pair(u, v)), Get(v, 1);
      else
        Get(v, 0);
    }
}
inline pair<int, int> Work(int u) {
  while (!vis[u]) vis[u] = 1, u = f[u];
  r = id[u], Dfs(u);
  pair<int, int> ans = dp[u][0];
  V.clear(), Get(u, 0), u = f[u], r = id[u], Dfs(u);
  return ans < dp[u][0] ? V.clear(), Get(u, 0), dp[u][0] : ans;
}
int main() {
  n = rd();
  for (register int i = 1; i <= n; ++i)
    f[i] = rd(), Add(f[i], i), id[i] = cnt, s[i] = rd() - 1;
  for (register int i = 1; i <= n; ++i)
    if (!vis[i]) ans = ans + Work(i), A.insert(A.end(), V.begin(), V.end());
  rt(ans.first), pc(' '), rt(ans.second), pc('\n');
  for (register int i = 0; i < (int)A.size(); ++i)
    rt(A[i].first), pc(' '), rt(A[i].second), pc('\n');
  return flush(), 0;
}
inline char gc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Len, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline int rd() {
  char c;
  while (!isdigit(c = gc()) && c != '-')
    ;
  int f = c == '-' ? c = gc(), 1 : 0, x = c ^ 48;
  while (isdigit(c = gc())) x = ((x + (x << 2)) << 1) + (c ^ 48);
  return f ? -x : x;
}
inline void pc(char c) {
  q1 == duf + Len &&fwrite(q1 = duf, 1, Len, stdout), *q1++ = c;
}
inline void rt(int x) {
  x < 0 ? pc('-'), x = -x : 0, pc((x >= 10 ? rt(x / 10), x % 10 : x) + 48);
}
inline void flush() { fwrite(duf, 1, q1 - duf, stdout); }