#include <bits/stdc++.h>
using namespace std;
struct df {
  int dq, bh;
} hd[100010], bd[100010];
int lh = 0, lb = 0;
int n;
bool px(df a, df b) { return a.dq < b.dq; }
int main() {
  cin >> n;
  int tmp1;
  for (int i = 0; i < n; i++) {
    cin >> tmp1;
    if (tmp1) {
      cin >> hd[lh].dq;
      hd[lh].bh = i + 1;
      lh++;
    } else {
      cin >> bd[lb].dq;
      bd[lb].bh = i + 1;
      lb++;
    }
  }
  sort(hd, hd + lh, px);
  sort(bd, bd + lb, px);
  int sh = 0, sb = 0, js = 0;
  while (sh < lh || sb < lb) {
    if (sh == lh && js < n - 1) {
      sb++;
      cout << hd[0].bh << ' ' << bd[sb].bh << ' ' << 0;
      js++;
    }
    if (sb == lb && js < n - 1) {
      sh++;
      cout << hd[sh].bh << ' ' << bd[0].bh << ' ' << 0 << endl;
      js++;
    }
    if (js == n - 1) break;
    if (sh < lh && sb < lb)
      if (hd[sh].dq < bd[sb].dq) {
        js++;
        cout << hd[sh].bh << ' ' << bd[sb].bh << ' ' << hd[sh].dq << endl;
        bd[sb].dq -= hd[sh].dq;
        hd[sh].dq = 0;
        sh++;
      } else {
        js++;
        cout << hd[sh].bh << ' ' << bd[sb].bh << ' ' << bd[sb].dq << endl;
        hd[sh].dq -= bd[sb].dq;
        bd[sb].dq = 0;
        sb++;
      }
  }
  return 0;
}
