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 inf = 2000 * 1000 * 1000;
const long long linf = 2000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
const int nmax = 100005;
int n;
int sex[nmax];
vector<int> g[nmax];
pair<int, int> dp[nmax][2];
bool used[nmax][2];
int p[nmax][2];
set<pair<int, int> > gr;
bool solved[nmax];
vector<pair<int, int> > ans;
vector<pair<int, int> > tmp;
vector<pair<int, int> > tmp2;
pair<int, int> total;
pair<int, int> virt_edge;
pair<int, int> virt_vert;
int visited[nmax];
int was[nmax];
int T = 0;
bool find_cycle(int v, int p, pair<int, int> &ret) {
  visited[v] = 1;
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == p || visited[to] == 2) continue;
    if (visited[to] == 1) {
      ret = make_pair(v, to);
      return true;
    }
    if (find_cycle(to, v, ret)) return true;
  }
  visited[v] = 2;
  return false;
}
void FILL(int v) {
  was[v] = T;
  solved[v] = true;
  used[v][0] = false;
  used[v][1] = false;
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (was[to] != T) FILL(to);
  }
}
pair<int, int> dfs(int v, int f, int P = -1) {
  if (used[v][f]) return dp[v][f];
  if ((int)g[v].size() == 0 || (int)g[v].size() == 1 && g[v][0] == P) {
    return make_pair(0, 0);
  }
  pair<int, int> &ret = dp[v][f];
  pair<int, int> cur = make_pair(0, 0), t, t2;
  p[v][f] = -1;
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == P) continue;
    if (make_pair(v, to) == virt_edge || make_pair(to, v) == virt_edge)
      continue;
    if (to == virt_vert.first || to == virt_vert.second)
      t = dfs(to, 1, v);
    else
      t = dfs(to, 0, v);
    cur.first += t.first;
    cur.second += t.second;
  }
  ret = cur;
  if (!f) {
    for (int i = 0; i < (int)g[v].size(); i++) {
      int to = g[v][i];
      if (to == P) continue;
      if (make_pair(v, to) == virt_edge || make_pair(to, v) == virt_edge)
        continue;
      if (to == virt_vert.first || to == virt_vert.second) continue;
      t = dfs(to, 0, v);
      t2 = dfs(to, 1, v);
      t2.first++;
      if (sex[v] != sex[to]) t2.second++;
      cur.first -= t.first;
      cur.second -= t.second;
      cur.first += t2.first;
      cur.second += t2.second;
      if (cur > ret) {
        ret = cur;
        p[v][f] = to;
      }
      cur.first += t.first;
      cur.second += t.second;
      cur.first -= t2.first;
      cur.second -= t2.second;
    }
  }
  used[v][f] = true;
  return ret;
}
void rec(int v, int f, vector<pair<int, int> > &tmp, int P = -1) {
  if ((int)g[v].size() == 0 || (int)g[v].size() == 1 && g[v][0] == P) {
    return;
  }
  if (!f && p[v][f] != -1) {
    tmp.push_back(make_pair(v, p[v][f]));
  }
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == P) continue;
    if (make_pair(v, to) == virt_edge || make_pair(to, v) == virt_edge)
      continue;
    if (to == virt_vert.first || to == virt_vert.second || to == p[v][f])
      rec(to, 1, tmp, v);
    else
      rec(to, 0, tmp, v);
  }
  return;
}
void go(int v) {
  pair<int, int> cur = make_pair(-1, -1), cur2;
  T++;
  FILL(v);
  virt_edge = make_pair(-1, -1);
  virt_vert = make_pair(-1, -1);
  tmp.clear();
  tmp2.clear();
  if (find_cycle(v, -1, virt_edge)) {
    cur = dfs(v, 0);
    rec(v, 0, tmp);
    T++;
    FILL(v);
    virt_vert = virt_edge;
    if (v != virt_vert.first && v != virt_vert.second) {
      cur2 = dfs(v, 0);
      rec(v, 0, tmp2);
    } else {
      cur2 = dfs(v, 1);
      rec(v, 1, tmp2);
    }
    tmp2.push_back(virt_edge);
    cur2.first++;
    if (sex[virt_vert.first] != sex[virt_vert.second]) cur2.second++;
    if (cur2 > cur) {
      cur = cur2;
      tmp = tmp2;
    }
    for (int i = 0; i < (int)tmp.size(); i++) ans.push_back(tmp[i]);
    total.first += cur.first;
    total.second += cur.second;
  } else {
    cur = dfs(v, 0);
    rec(v, 0, tmp);
    for (int i = 0; i < (int)tmp.size(); i++) ans.push_back(tmp[i]);
    total.first += cur.first;
    total.second += cur.second;
  }
}
bool solve() {
  int a, b, c;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a = i;
    scanf("%d%d", &b, &c);
    b--;
    if (a > b) swap(a, b);
    if (gr.find(make_pair(a, b)) == gr.end()) {
      g[a].push_back(b);
      g[b].push_back(a);
      gr.insert(make_pair(a, b));
    }
    sex[i] = c;
  }
  memset((solved), false, sizeof(solved));
  total = make_pair(0, 0);
  for (int i = 0; i < n; i++) {
    if (!solved[i]) {
      go(i);
    }
  }
  printf("%d %d\n", total.first, total.second);
  if ((int)ans.size() < total.first) {
    printf("4to to ne tak\n");
  }
  for (int i = 0; i < (int)ans.size(); i++) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}