#include <bits/stdc++.h>
using namespace std;
int s[200010];
int a[200010], b[200010];
int main() {
  int p, q;
  int t, ta, tb;
  int i;
  int n;
  while (scanf("%d", &n) != EOF) {
    p = q = -1;
    for (i = 1; i <= n; i++) {
      scanf("%d%d", &t, &s[i]);
      if (t)
        a[++p] = i;
      else
        b[++q] = i;
    }
    for (i = 0; i < n - 1; i++) {
      ta = a[p];
      tb = b[q];
      t = min(s[ta], s[tb]);
      printf("%d %d %d\n", ta, tb, t);
      s[ta] -= t;
      s[tb] -= t;
      if (s[ta] == 0 && s[tb] == 0) {
        if (p <= q)
          q--;
        else
          p--;
      } else {
        if (s[ta] == 0)
          p--;
        else
          q--;
      }
    }
  }
  return 0;
}
