#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e5 + 20;
struct Edges {
  int v;
  int u;
  int w;
} e[MAX_N];
set<pair<int, int> > White;
set<pair<int, int> > Black;
set<pair<int, int> >::iterator itW;
set<pair<int, int> >::iterator itB;
bool mark[MAX_N];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int color, s;
    cin >> color >> s;
    if (color)
      Black.insert(make_pair(s, i + 1));
    else
      White.insert(make_pair(s, i + 1));
  }
  int head = 0;
  while (head < n - 1) {
    itW = White.begin();
    itB = Black.begin();
    pair<int, int> B = *itB, W = *itW;
    int tmp = 0;
    if (B.first <= W.first) {
      if (B.first == W.first) tmp = 1;
      e[head].v = B.second;
      e[head].u = W.second;
      e[head].w = B.first;
      Black.erase(B);
      White.erase(W);
      W.first -= B.first;
      B.first = 0;
      if (!tmp)
        mark[B.second] = 1;
      else {
        if (White.size() < Black.size() + 1)
          mark[B.second] = 1;
        else
          mark[W.second] = 1;
      }
    } else {
      e[head].v = B.second;
      e[head].u = W.second;
      e[head].w = W.first;
      Black.erase(B);
      White.erase(W);
      B.first -= W.first;
      W.first = 0;
      mark[W.second] = 1;
    }
    if (!mark[B.second]) Black.insert(B);
    if (!mark[W.second]) White.insert(W);
    head++;
  }
  for (int i = 0; i < head; i++)
    cout << e[i].v << ' ' << e[i].u << ' ' << e[i].w << endl;
}
