#include <bits/stdc++.h>
using namespace std;
int ad1, ad2, n;
struct node {
  int su, id;
};
struct node a[100005], b[100005];
bool cmp(struct node x, struct node y) { return x.su < y.su; }
int main() {
  scanf("%d", &n);
  int col, su;
  ad1 = ad2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &col, &su);
    if (col) {
      a[++ad1].su = su;
      a[ad1].id = i;
    } else {
      b[++ad2].su = su;
      b[ad2].id = i;
    }
  }
  sort(a + 1, a + 1 + ad1, cmp);
  sort(b + 1, b + 1 + ad2, cmp);
  for (int i = 1, j = 1; i <= ad1 && j <= ad2;) {
    int tmp = min(a[i].su, b[j].su);
    printf("%d %d %d\n", a[i].id, b[j].id, tmp);
    a[i].su -= tmp;
    b[j].su -= tmp;
    if (a[i].su)
      j++;
    else if (b[j].su)
      i++;
    else if (i < ad1)
      i++;
    else
      j++;
  }
  return 0;
}
