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>
#pragma GCC optimize(3)
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inf_ll = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5 + 100;
vector<int> E[maxn];
vector<int> chain;
int color[maxn];
int vis[maxn];
int n;
bool in_chain[maxn];
pair<int, int> dp[maxn][2];
int pre[maxn];
stack<int> stk;
template <typename T, typename U>
pair<T, U> operator+(const pair<T, U> &x, const pair<T, U> &y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
template <typename T, typename U>
pair<T, U> operator-(const pair<T, U> &x, const pair<T, U> &y) {
  return make_pair(x.first - y.first, x.second - y.second);
}
void dfs_dp(int u) {
  dp[u][0] = make_pair(0, 0);
  for (int v : E[u]) {
    if (in_chain[v]) continue;
    dfs_dp(v);
    dp[u][0] = dp[u][0] + max(dp[v][0], dp[v][1]);
  }
  dp[u][1] = dp[u][0];
  pair<int, int> max_del = make_pair(-inf, -inf);
  for (int v : E[u]) {
    if (in_chain[v]) continue;
    auto del = dp[v][0] - max(dp[v][0], dp[v][1]);
    del.first++;
    if (color[v] ^ color[u]) del.second++;
    if (del > max_del) {
      max_del = del;
      pre[u] = v;
    }
  }
  dp[u][1] = dp[u][1] + max_del;
}
void dfs_ans(int u, int flag, vector<pair<int, int> > &dp_ans) {
  for (int v : E[u]) {
    if (in_chain[v]) continue;
    if (flag == 1 && v == pre[u]) {
      dp_ans.push_back(make_pair(u, pre[u]));
      dfs_ans(v, 0, dp_ans);
    } else {
      if (dp[v][1] > dp[v][0]) {
        dfs_ans(v, 1, dp_ans);
      } else {
        dfs_ans(v, 0, dp_ans);
      }
    }
  }
}
void dfs(int u) {
  vis[u] = 1;
  stk.push(u);
  for (int v : E[u]) {
    if (!vis[v])
      dfs(v);
    else if (vis[v] == 2)
      continue;
    else if (vis[v] == 1) {
      while (1) {
        chain.push_back(stk.top());
        vis[stk.top()] = 2;
        stk.pop();
        if (chain.back() == v) break;
      }
      while (!stk.empty()) {
        vis[stk.top()] = 2;
        stk.pop();
      }
      reverse(chain.begin(), chain.end());
      for (int x : chain) in_chain[x] = 1;
      throw 1;
    } else
      assert(0);
  }
  vis[u] = 2;
  stk.pop();
}
vector<pair<int, int> > ans(0);
pair<int, int> DP[maxn][2];
bool used[maxn];
pair<pair<int, int>, vector<pair<int, int> > > dp_ans() {
  for (int x : chain) used[x] = 0;
  int pre = 0;
  for (int x : chain) {
    for (int i = 0; i < 2; i++) {
      DP[x][i] = max(DP[pre][0], DP[pre][1]) + dp[x][i];
    }
    if (pre) {
      pair<int, int> temp_dp =
          DP[pre][0] + dp[x][0] + make_pair(1, (int)(color[x] != color[pre]));
      if (temp_dp > DP[x][1]) {
        DP[x][1] = temp_dp;
        used[x] = 1;
      }
    }
    pre = x;
  }
  vector<pair<int, int> > mans(0);
  vector<int> chain = ::chain;
  int now, flag;
  int edp = chain.back();
  now = chain.back();
  if (DP[now][1] > DP[now][0])
    flag = 1;
  else
    flag = 0;
  chain.pop_back();
  if (flag == 1 && used[now])
    dfs_ans(now, 0, mans);
  else
    dfs_ans(now, flag, mans);
  while (!chain.empty()) {
    int tail = chain.back();
    chain.pop_back();
    if (flag == 1 && used[now]) {
      mans.push_back(make_pair(tail, now));
      now = tail;
      flag = 0;
    } else {
      if (DP[tail][1] > DP[tail][0])
        flag = 1;
      else
        flag = 0;
      now = tail;
    }
    if (flag == 1 && used[now])
      dfs_ans(now, 0, mans);
    else
      dfs_ans(now, flag, mans);
  }
  return make_pair(max(DP[edp][0], DP[edp][1]), mans);
}
pair<int, int> dp_out;
void work() {
  for (int root : chain) {
    dfs_dp(root);
  }
  pair<int, int> dp1;
  vector<pair<int, int> > ans1;
  tie(dp1, ans1) = dp_ans();
  int head = chain.front();
  reverse(chain.begin(), chain.end());
  chain.pop_back();
  reverse(chain.begin(), chain.end());
  chain.push_back(head);
  pair<int, int> dp2;
  vector<pair<int, int> > ans2;
  tie(dp2, ans2) = dp_ans();
  if (dp1 > dp2) {
    dp_out = dp_out + dp1;
    ans.insert(ans.end(), ans1.begin(), ans1.end());
  } else {
    dp_out = dp_out + dp2;
    ans.insert(ans.end(), ans2.begin(), ans2.end());
  }
}
void search_chain() {
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      while (!stk.empty()) stk.pop();
      try {
        dfs(i);
      } catch (int x) {
        work();
        chain.clear();
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int v;
    cin >> v >> color[i];
    E[v].push_back(i);
  }
  search_chain();
  cout << dp_out.first << " " << dp_out.second << endl;
  for (auto pr : ans) {
    int u, v;
    tie(u, v) = pr;
    cout << v << " " << u << endl;
  }
  return 0;
}