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 BUF = 100005;
class Edge {
 public:
  int src, dst;
  Edge() {}
  Edge(int s, int d) : src(s), dst(d) {}
};
int nNode, nex[BUF];
bool isMale[BUF];
bool read() {
  if (!(cin >> nNode)) return false;
  for (int i = 0; i < nNode; i++) {
    int maleId;
    scanf("%d%d", &nex[i], &maleId);
    nex[i]--;
    isMale[i] = maleId == 1;
  }
  return true;
}
bool finished[BUF];
pair<int, int> rec(int curAvail, int cur, pair<int, int> dp[2][BUF],
                   vector<int> adj[BUF]) {
  finished[cur] = true;
  pair<int, int> &ret = dp[curAvail][cur];
  if (ret != make_pair(-1, -1)) return ret;
  ret = make_pair(0, 0);
  if (curAvail) {
    pair<int, int> sum = make_pair(0, 0);
    for (int i = 0; i < adj[cur].size(); i++) {
      pair<int, int> t = rec(1, adj[cur][i], dp, adj);
      sum.first += t.first;
      sum.second += t.second;
    }
    ret = sum;
    for (int i = 0; i < adj[cur].size(); i++) {
      pair<int, int> t = rec(1, adj[cur][i], dp, adj),
                     s = rec(0, adj[cur][i], dp, adj);
      int boygirl = isMale[cur] != isMale[adj[cur][i]];
      int fst = sum.first - t.first + s.first + 1;
      int scd = sum.second - t.second + s.second + boygirl;
      ret = max(ret, make_pair(fst, scd));
    }
  } else {
    for (int i = 0; i < adj[cur].size(); i++) {
      pair<int, int> t = rec(1, adj[cur][i], dp, adj);
      ret.first += t.first;
      ret.second += t.second;
    }
  }
  return ret;
}
void getAns(int curAvail, int cur, pair<int, int> dp[2][BUF], vector<Edge> &ans,
            vector<int> adj[BUF]) {
  if (curAvail) {
    int connect = -1;
    pair<int, int> maxV;
    pair<int, int> sum = make_pair(0, 0);
    for (int i = 0; i < adj[cur].size(); i++) {
      pair<int, int> t = dp[1][adj[cur][i]];
      sum.first += t.first;
      sum.second += t.second;
    }
    maxV = sum;
    for (int i = 0; i < adj[cur].size(); i++) {
      pair<int, int> t = dp[1][adj[cur][i]], s = dp[0][adj[cur][i]];
      int boygirl = isMale[cur] != isMale[adj[cur][i]];
      int fst = sum.first - t.first + s.first + 1;
      int scd = sum.second - t.second + s.second + boygirl;
      if (maxV < make_pair(fst, scd)) {
        maxV = make_pair(fst, scd);
        connect = adj[cur][i];
      }
    }
    if (connect != -1) ans.push_back(Edge(cur, connect));
    for (int i = 0; i < adj[cur].size(); i++)
      getAns(adj[cur][i] == connect ? 0 : 1, adj[cur][i], dp, ans, adj);
  } else {
    for (int i = 0; i < adj[cur].size(); i++)
      getAns(1, adj[cur][i], dp, ans, adj);
  }
}
void work() {
  memset(finished, 0, sizeof(finished));
  vector<int> adj[BUF];
  for (int i = 0; i < nNode; i++) adj[nex[i]].push_back(i);
  pair<int, int> num = make_pair(0, 0);
  vector<Edge> ans;
  static pair<int, int> dp[2][2][BUF];
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < nNode; i++) {
    if (finished[i]) continue;
    int toCalc = i;
    while (!finished[toCalc]) {
      finished[toCalc] = true;
      toCalc = nex[toCalc];
    }
    int src = nex[toCalc], dst = toCalc;
    adj[src].erase(find(adj[src].begin(), adj[src].end(), dst));
    pair<int, int> A = rec(1, dst, dp[0], adj);
    adj[src].push_back(dst);
    src = nex[nex[toCalc]], dst = nex[toCalc];
    adj[src].erase(find(adj[src].begin(), adj[src].end(), dst));
    pair<int, int> B = rec(1, dst, dp[1], adj);
    adj[src].push_back(dst);
    if (A > B) {
      num.first += A.first;
      num.second += A.second;
      src = nex[toCalc], dst = toCalc;
      adj[src].erase(find(adj[src].begin(), adj[src].end(), dst));
      getAns(1, dst, dp[0], ans, adj);
    } else {
      num.first += B.first;
      num.second += B.second;
      src = nex[nex[toCalc]], dst = nex[toCalc];
      adj[src].erase(find(adj[src].begin(), adj[src].end(), dst));
      getAns(1, dst, dp[1], ans, adj);
    }
  }
  cout << num.first << ' ' << num.second << endl;
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].src + 1, ans[i].dst + 1);
}
int main() {
  while (read()) work();
  return 0;
}