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 N = 1e5 + 9;
int n, u, v, v1, v2, v3, x, s, w[N], d[N], vis[N], mark[N];
pair<int, int> ans, dp1[N], dp2[N];
vector<pair<int, int> > pairs, e;
vector<int> g[N];
void del_edge(int x, int y) {
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] == y) {
      g[x].erase(g[x].begin() + i);
      break;
    }
  for (int i = 0; i < g[y].size(); i++)
    if (g[y][i] == x) {
      g[y].erase(g[y].begin() + i);
      break;
    }
}
void dfs(int x, int par) {
  pair<int, int> p, e;
  dp1[x].first = dp1[x].second = dp2[x].first = dp2[x].second = 0;
  p.first = p.second = 0;
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par) {
      dfs(g[x][i], x);
      e = make_pair(
          dp2[g[x][i]].first - dp1[g[x][i]].first + 1,
          dp2[g[x][i]].second - dp1[g[x][i]].second + (w[x] != w[g[x][i]]));
      if (e > p) p = e, d[x] = g[x][i];
      dp2[x].first += dp1[g[x][i]].first, dp2[x].second += dp1[g[x][i]].second;
      ;
    }
  dp1[x] = dp2[x];
  dp1[x].first += p.first, dp1[x].second += p.second;
  ;
}
void dfs1(int x, int par) {
  int io = 0;
  vis[x] = 1;
  for (int i = 0; i < g[x].size(); i++) {
    if ((vis[g[x][i]] && (g[x][i] != par || io == 1)))
      v1 = par, v2 = x, v3 = g[x][i];
    io += (g[x][i] == par);
  }
  for (int i = 0; i < g[x].size(); i++)
    if (!vis[g[x][i]]) dfs1(g[x][i], x);
}
void calc_pairs(int x, int par, int src) {
  if (dp1[x] == dp2[x]) src = 1;
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par) {
      if (g[x][i] == d[x] && src == 0) {
        e.push_back(make_pair(x, g[x][i]));
        calc_pairs(g[x][i], x, 1);
      } else
        calc_pairs(g[x][i], x, 0);
    }
}
void solve(int root) {
  pair<int, int> res;
  res.first = res.second = 0, v1 = v2 = v3 = 0;
  e.clear();
  dfs1(root, 0);
  del_edge(v1, v2);
  dfs(root, 0);
  calc_pairs(root, 0, 0);
  res = dp1[root];
  g[v1].push_back(v2), g[v2].push_back(v1);
  del_edge(v2, v3);
  dfs(root, 0);
  if (dp1[root] > res) {
    e.clear();
    res = dp1[root];
    calc_pairs(root, 0, 0);
  }
  for (int i = 0; i < e.size(); i++) pairs.push_back(e[i]);
  ans.first += res.first, ans.second += res.second;
  ;
}
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> u >> w[i];
    g[i].push_back(u);
    g[u].push_back(i);
    w[i]--;
  }
  for (int i = 1; i < n + 1; i++)
    if (!vis[i]) solve(i);
  cout << ans.first << " " << ans.second << endl;
  for (int i = 0; i < pairs.size(); i++)
    cout << pairs[i].first << " " << pairs[i].second << endl;
}