#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int pos, sum;
} node;
bool cmp(node x, node y) { return x.sum > y.sum; }
node c1[100009], c0[100009];
int main() {
  int n;
  scanf("%d", &n);
  int tot0 = 0, tot1 = 0;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == 0) {
      c0[tot0].pos = i;
      c0[tot0].sum = y;
      tot0++;
    } else {
      c1[tot1].pos = i;
      c1[tot1].sum = y;
      tot1++;
    }
  }
  sort(c1, c1 + tot1, cmp);
  sort(c0, c0 + tot0, cmp);
  int cur = c0[0].pos;
  int sum = c0[0].sum;
  int c = 0;
  int i = 1, j = 0;
  while (i < tot0 || j < tot1) {
    if (c == 0) {
      int pos = c1[j].pos;
      int tmp = c1[j].sum;
      if (j >= tot1) break;
      j++;
      printf("%d %d %d\n", cur, pos, min(tmp, sum));
      if (tmp < sum) {
        sum -= tmp;
      } else {
        sum = tmp - sum;
        c = 1;
        cur = pos;
      }
    } else {
      int pos = c0[i].pos;
      int tmp = c0[i].sum;
      if (i >= tot0) break;
      i++;
      printf("%d %d %d\n", cur, pos, min(tmp, sum));
      if (tmp < sum)
        sum -= tmp;
      else {
        sum = tmp - sum;
        c = 0;
        cur = pos;
      }
    }
  }
  for (; i < tot0; i++) printf("%d %d 0\n", c0[i].pos, c1[0].pos);
  for (; j < tot1; j++) printf("%d %d 0\n", c1[j].pos, c0[0].pos);
}
