#include <bits/stdc++.h>
using namespace std;
struct node {
  int ind, val;
};
bool operator<(const node &a, const node &b) {
  if (a.val != b.val) return a.val > b.val;
  return a.ind > b.ind;
}
priority_queue<node> one, zero;
struct triple {
  int v, u, w;
};
vector<triple> res;
int main() {
  int n, c, s, o, z;
  triple x;
  node temp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c, &s);
    temp.ind = i;
    temp.val = s;
    if (c) {
      one.push(temp);
    } else {
      zero.push(temp);
    }
  }
  while (!one.empty() && !zero.empty()) {
    if (one.top().val < zero.top().val) {
      o = one.top().ind;
      z = zero.top().ind;
      x.u = one.top().ind;
      x.v = zero.top().ind;
      x.w = one.top().val;
      res.push_back(x);
      one.pop();
      temp = zero.top();
      zero.pop();
      temp.val -= x.w;
      zero.push(temp);
    } else {
      o = one.top().ind;
      z = zero.top().ind;
      x.u = one.top().ind;
      x.v = zero.top().ind;
      x.w = zero.top().val;
      res.push_back(x);
      zero.pop();
      temp = one.top();
      one.pop();
      temp.val -= x.w;
      one.push(temp);
    }
  }
  if (!one.empty()) one.pop();
  while (!one.empty()) {
    x.u = one.top().ind;
    x.v = z;
    x.w = 0;
    res.push_back(x);
    one.pop();
  }
  if (!zero.empty()) zero.pop();
  while (!zero.empty()) {
    x.u = zero.top().ind;
    x.v = o;
    x.w = 0;
    res.push_back(x);
    zero.pop();
  }
  for (int i = 0; i < n - 1; i++)
    printf("%d %d %d\n", res[i].u + 1, res[i].v + 1, res[i].w);
  return 0;
}
