#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > A, B;
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int c, s;
    scanf("%d%d", &c, &s);
    if (c)
      A.push(make_pair(-s, i));
    else
      B.push(make_pair(-s, i));
  }
  while (true) {
    if (A.size() && B.size()) {
      pair<int, int> a = A.top();
      A.pop();
      pair<int, int> b = B.top();
      B.pop();
      a.first *= -1, b.first *= -1;
      if (a.first > b.first) {
        printf("%d %d %d\n", a.second, b.second, b.first);
        A.push(make_pair(-(a.first - b.first), a.second));
      } else if (a.first < b.first) {
        printf("%d %d %d\n", a.second, b.second, a.first);
        B.push(make_pair(-(b.first - a.first), b.second));
      } else {
        if (A.size() > B.size()) {
          printf("%d %d %d\n", a.second, b.second, a.first);
          B.push(make_pair(-(b.first - a.first), b.second));
        } else {
          printf("%d %d %d\n", a.second, b.second, b.first);
          A.push(make_pair(-(a.first - b.first), a.second));
        }
      }
    } else
      break;
  }
  return 0;
}
