#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
struct Node {
  int id;
  long long val;
  bool operator<(const Node &b) const { return val > b.val; }
};
struct Videge {
  int fa, son;
  long long w;
} v[maxn];
priority_queue<Node> pq1, pq2;
int main() {
  int n, m, k;
  long long a;
  scanf("%d", &n);
  Node md;
  for (int i = 1; i <= n; i++) {
    scanf("%d%I64dd", &k, &a);
    md.id = i;
    md.val = a;
    if (k)
      pq1.push(md);
    else
      pq2.push(md);
  }
  Node bi, wi;
  m = n;
  n - n - 1;
  while (n--) {
    wi = pq1.top();
    pq1.pop();
    bi = pq2.top();
    pq2.pop();
    if (wi.val < bi.val) {
      v[n].fa = wi.id;
      v[n].son = bi.id;
      v[n].w = wi.val;
      int r = bi.val - wi.val;
      bi.val = r;
      pq2.push(bi);
    } else {
      v[n].fa = bi.id;
      v[n].son = wi.id;
      v[n].w = bi.val;
      int r = wi.val - bi.val;
      wi.val = r;
      pq1.push(wi);
    }
  }
  for (int i = 1; i < m; i++) {
    printf("%d %d %I64d\n", v[i].fa, v[i].son, v[i].w);
  }
}
