#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  while (~scanf("%d", &n)) {
    queue<pair<int, int> > B, W;
    int c, s;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &c, &s);
      if (c == 0)
        B.push(make_pair(s, i));
      else
        W.push(make_pair(s, i));
    }
    pair<int, int> w, b;
    int cnt = 0;
    while (cnt < n - 1) {
      w = W.front(), b = B.front();
      W.pop(), B.pop();
      if (w.first > b.first) {
        printf("%d %d %d\n", b.second, w.second, b.first);
        w.first -= b.first;
        W.push(w);
      } else if (w.first < b.first) {
        printf("%d %d %d\n", w.second, b.second, w.first);
        b.first -= w.first;
        B.push(b);
      } else {
        printf("%d %d %d\n", b.second, w.second, b.first);
        if (W.empty())
          W.push(make_pair(0, w.second));
        else
          B.push(make_pair(0, b.second));
      }
      cnt++;
    }
  }
  return 0;
}
