#include <bits/stdc++.h>
using namespace std;
unsigned long long sw[100001], sb[100001];
int ind[2][100001];
void printE(int u, int v, unsigned long long w) {
  int ui = ind[1][u];
  int vi = ind[0][v];
  cout << ui + 1 << " " << vi + 1 << " " << w << endl;
}
int main() {
  int n;
  cin >> n;
  int nw = 0, nb = 0;
  int c;
  unsigned long long s;
  for (int i = 0; i < n; i++) {
    cin >> c >> s;
    if (c == 0) {
      sw[nw] = s;
      ind[0][nw] = i;
      nw++;
    } else if (c == 1) {
      sb[nb] = s;
      ind[1][nb] = i;
      nb++;
    }
  }
  int cl = 0;
  int ib = 0;
  int iw = 0;
  while (1) {
    if (sb[ib] > sw[iw]) {
      sb[ib] = sb[ib] - sw[iw];
      printE(ib, iw, sw[iw]);
      iw++;
      cl = 1;
    } else {
      sw[iw] = sw[iw] - sb[ib];
      printE(ib, iw, sb[ib]);
      ib++;
      cl = 0;
    }
    if (iw >= nw || ib >= nb) break;
  }
  if (cl == 1) {
    for (int i = ib + 1; i < nb; i++) {
      printE(i, iw - 1, 0);
    }
  } else {
    for (int i = iw + 1; i < nw; i++) {
      printE(ib - 1, i, 0);
    }
  }
  return 0;
}
