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;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
const int MAXN = 111111;
int color[MAXN];
vector<int> adj[MAXN];
bool visited[MAXN];
vector<pair<int, int> > solution;
pair<int, int> restrictedEdge;
bool operator<(const complex<int>& X, const complex<int>& Y) {
  return pair<int, int>(X.real(), X.imag()) <
         pair<int, int>(Y.real(), Y.imag());
}
void dfs(int u, int p = -1) {
  visited[u] = true;
  for (int i = (0); i < ((int)adj[u].size()); ++i) {
    int v = adj[u][i];
    if (v == p) continue;
    if (visited[v])
      restrictedEdge = pair<int, int>(u, v);
    else
      dfs(v, u);
  }
}
int loadedU;
int counted[MAXN][2];
complex<int> memo[MAXN][2];
int cc = 0;
complex<int> f(int u, int p, int used, vector<pair<int, int> >& solution,
               bool construct) {
  if (!construct && counted[u][used] == cc) return memo[u][used];
  counted[u][used] = cc;
  complex<int> ret(0, 0);
  if (used == 0) {
    if (loadedU == u) return memo[u][used] = f(u, p, 1, solution, construct);
    complex<int> S(0, 0);
    for (int i = (0); i < ((int)adj[u].size()); ++i) {
      int v = adj[u][i];
      if (v == p) continue;
      S += f(v, u, 0, solution, false);
    }
    ret = S;
    int maxv = -1;
    for (int i = (0); i < ((int)adj[u].size()); ++i) {
      int v = adj[u][i];
      if (v == p || v == loadedU) continue;
      complex<int> X = S - f(v, u, 0, solution, false) +
                       f(v, u, 1, solution, false) +
                       complex<int>(1, color[v] ^ color[u]);
      if (ret < X) {
        ret = X;
        maxv = v;
      }
    }
    if (construct) {
      for (int i = (0); i < ((int)adj[u].size()); ++i) {
        int v = adj[u][i];
        if (v == p) continue;
        if (v != maxv)
          f(v, u, 0, solution, true);
        else {
          f(v, u, 1, solution, true);
          solution.push_back(pair<int, int>(u, v));
        }
      }
    }
  } else {
    for (int i = (0); i < ((int)adj[u].size()); ++i) {
      int v = adj[u][i];
      if (v == p) continue;
      ret += f(v, u, 0, solution, construct);
    }
  }
  return memo[u][used] = ret;
}
complex<int> solve(int n) {
  complex<int> ret(0, 0);
  memset((counted), (-1), sizeof(counted));
  memset((visited), (false), sizeof(visited));
  for (int u = (1); u < (n + 1); ++u)
    if (!visited[u]) {
      ++cc;
      restrictedEdge = pair<int, int>(-1, -1);
      dfs(u);
      complex<int> ans[2];
      vector<pair<int, int> > curSolution[2];
      int best = 0;
      loadedU = restrictedEdge.first;
      if (loadedU == -1)
        ans[0] = ans[1] = f(u, u, 0, curSolution[0], true);
      else {
        adj[loadedU].erase(find(adj[loadedU].begin(), adj[loadedU].end(),
                                restrictedEdge.second));
        adj[restrictedEdge.second].erase(
            find(adj[restrictedEdge.second].begin(),
                 adj[restrictedEdge.second].end(), loadedU));
        loadedU = -1;
        int v = restrictedEdge.second;
        ans[0] = f(v, v, 0, curSolution[0], true);
        loadedU = restrictedEdge.first;
        ++cc;
        curSolution[1].push_back(pair<int, int>(loadedU, v));
        ans[1] = f(v, v, 1, curSolution[1], true) +
                 complex<int>(1, color[loadedU] ^ color[v]);
        if (ans[0] < ans[1]) best = 1;
        ret += ans[best];
      }
      solution.insert(solution.end(), curSolution[best].begin(),
                      curSolution[best].end());
    }
  return ret;
}
int main() {
  memset((color), (0), sizeof(color));
  int n;
  cin >> n;
  for (int u = (1); u < (n + 1); ++u) {
    int f, s;
    cin >> f >> s;
    color[u] = s - 1;
    adj[u].push_back(f);
    adj[f].push_back(u);
  }
  complex<int> ans = solve(n);
  cout << ans.real() << " " << ans.imag() << endl;
  for (int i = (0); i < ((int)solution.size()); ++i)
    printf("%d %d\n", solution[i].first, solution[i].second);
  return 0;
}