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;
long long int n;
vector<long long int> g[100010];
bool found = 0;
bool sex[100010];
long long int frnd[100010];
long long int x1, x2, x3;
map<pair<long long int, long long int>, long long int> m1;
long long int offset = 1000000;
long long int nxt = 1;
long long int dp[1000000];
vector<pair<long long int, long long int> > op;
void DFSH(long long int id, bool visited[], long long int p) {
  visited[id] = 1;
  for (auto v : g[id]) {
    if (visited[v] == 1 && v != p && found == 0) {
      x1 = p;
      x2 = id;
      x3 = v;
      found = 1;
    }
    if (visited[v] == 0) DFSH(v, visited, id);
  }
}
long long int fun(long long int u, long long int p) {
  long long int index = m1[make_pair(u, p)];
  if (index != 0) {
    return dp[index];
  }
  long long int a1 = 0;
  for (auto v : g[u]) {
    if (v != p && v != -1) {
      a1 += fun(v, u);
    }
  }
  long long int a2;
  long long int mx = a1;
  for (auto v : g[u]) {
    if (v != p && v != -1) {
      if (sex[u] != sex[v])
        a2 = offset + 1;
      else
        a2 = offset;
      a2 += a1 - fun(v, u);
      for (auto v1 : g[v]) {
        if (v1 != u && v1 != -1) {
          a2 += fun(v1, v);
        }
      }
      mx = max(mx, a2);
    }
  }
  m1[make_pair(u, p)] = nxt;
  dp[nxt] = mx;
  nxt++;
  return mx;
}
long long int pfun(long long int u, long long int p) {
  long long int index = m1[make_pair(u, p)];
  long long int xyz = dp[index];
  long long int a1 = 0;
  for (auto v : g[u]) {
    if (v != p && v != -1) {
      a1 += fun(v, u);
    }
  }
  if (xyz == a1) {
    for (auto v : g[u]) {
      if (v != p && v != -1) {
        pfun(v, u);
      }
    }
    return dp[index];
  }
  long long int a2;
  for (auto v : g[u]) {
    if (v != p && v != -1) {
      if (sex[u] != sex[v])
        a2 = offset + 1;
      else
        a2 = offset;
      a2 += a1 - fun(v, u);
      for (auto v1 : g[v]) {
        if (v1 != u && v1 != -1) {
          a2 += fun(v1, v);
        }
      }
      if (a2 == xyz) {
        op.push_back(make_pair(u + 1, v + 1));
        for (auto v1 : g[u]) {
          if (v1 != p && v1 != -1 && v1 != v) {
            pfun(v1, u);
          }
        }
        for (auto v1 : g[v]) {
          if (v1 != u && v1 != -1) {
            a2 += pfun(v1, v);
          }
        }
        return dp[index];
      }
    }
  }
  return dp[index];
}
void solve() {
  long long int ans = 0, final = 0;
  bool visited[100010] = {0};
  for (int i = 0; i < n; i++) {
    if (visited[i] == 1) continue;
    found = 0;
    DFSH(i, visited, -1);
    ans = 0;
    if (found == 1) {
      for (auto &v : g[x1]) {
        if (v == x2) {
          v = -1;
          break;
        }
      }
      for (auto &v : g[x2]) {
        if (v == x1) {
          v = -1;
          break;
        }
      }
      m1.clear();
      ans = max(fun(i, -1), ans);
      m1.clear();
      for (auto &v : g[x1]) {
        if (v == -1) {
          v = x2;
          break;
        }
      }
      for (auto &v : g[x2]) {
        if (v == -1) {
          v = x1;
        } else if (v == x3) {
          v = -1;
        }
      }
      for (auto &v : g[x3]) {
        if (v == x2) {
          v = -1;
        }
      }
      ans = max(ans, fun(i, -1));
      if (ans == fun(i, -1)) {
        pfun(i, -1);
      } else {
        for (auto &v : g[x3]) {
          if (v == -1) {
            v = x2;
            break;
          }
        }
        for (auto &v : g[x2]) {
          if (v == -1) {
            v = x3;
          } else if (v == x1) {
            v = -1;
          }
        }
        for (auto &v : g[x1]) {
          if (v == x2) {
            v = -1;
          }
        }
        m1.clear();
        fun(i, -1);
        pfun(i, -1);
      }
    } else {
      m1.clear();
      ans = max(ans, fun(i, -1));
      pfun(i, -1);
    }
    final += ans;
  }
  cout << final / offset << " ";
  cout << final % offset << endl;
  long long int sss = op.size();
  for (int i = 0; i < sss; i++) {
    cout << op[i].first << " " << op[i].second << endl;
  }
}
int main() {
  long long int x, s;
  cin >> n;
  map<pair<long long int, long long int>, long long int> m3;
  for (long long int i = 0; i < n; i++) {
    cin >> x >> s;
    x--;
    s--;
    sex[i] = s;
    if (m3[make_pair(i, x)] == 0) {
      m3[make_pair(i, x)] = 1;
      m3[make_pair(x, i)] = 1;
      g[i].push_back(x);
      g[x].push_back(i);
    }
    frnd[i] = x;
  }
  solve();
  return 0;
}