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 double eps = 1e-8;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
int from[200007], n;
pair<int, int> p[200007];
vector<int> ch[200007];
pair<int, int> F[200007][2];
bool vis[200007];
void fuck(int u) {
  vis[u] = true;
  F[u][0] = F[u][1] = make_pair(0, 0);
  from[u] = -1;
  for (typeof(ch[u].begin()) it = ch[u].begin(); it != ch[u].end(); it++)
    fuck(*it);
  for (typeof(ch[u].begin()) it = ch[u].begin(); it != ch[u].end(); it++) {
    F[u][1] = F[u][1] + max(F[*it][0], F[*it][1]);
    pair<int, int> delt = make_pair(1, (p[u].second != p[*it].second));
    if (F[u][0] + F[*it][0] + delt > F[u][1]) {
      F[u][1] = F[u][0] + F[*it][0] + delt;
      from[u] = *it;
    }
    F[u][0] = F[u][0] + max(F[*it][0], F[*it][1]);
  }
}
vector<pair<int, int> > ansi;
vector<pair<int, int> > res;
void gaogao(int u, bool can) {
  for (typeof(ch[u].begin()) it = ch[u].begin(); it != ch[u].end(); it++)
    if (*it == from[u] && !can && !(F[u][1] < F[u][0])) {
      res.push_back(make_pair(u, *it));
      gaogao(*it, true);
    } else
      gaogao(*it, false);
}
pair<int, int> ans = make_pair(0, 0);
void gao(int u) {
  int v = u;
  while (!vis[v]) {
    vis[v] = true;
    v = p[v].first;
  }
  pair<int, int> tmp = make_pair(0, 0);
  for (int rep = 0; rep < 2; rep++) {
    int w = p[v].first;
    ch[w].erase(find(ch[w].begin(), ch[w].end(), v));
    fuck(v);
    if (max(F[v][0], F[v][1]) > tmp) {
      tmp = max(F[v][0], F[v][1]);
      res.clear();
      gaogao(v, false);
    }
    ch[w].push_back(v);
    v = w;
  }
  ans = ans + tmp;
  for (typeof(res.begin()) it = res.begin(); it != res.end(); it++)
    ansi.push_back(*it);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    --p[i].first;
    ch[p[i].first].push_back(i);
  }
  ans = make_pair(0, 0);
  for (int i = 0; i < n; i++)
    if (!vis[i]) gao(i);
  cout << ans.first << " " << ans.second << endl;
  for (typeof(ansi.begin()) it = ansi.begin(); it != ansi.end(); it++)
    cout << it->first + 1 << " " << it->second + 1 << endl;
  return 0;
}