#include <bits/stdc++.h>
using namespace std;
struct _nl {
} nl;
bool _ns = 0;
template <typename T>
void _p(const T& _) {
  if constexpr (is_same<T, _nl>()) {
    cout << "\n";
    _ns = 0;
  } else {
    if (_ns) cout << " ";
    cout << _;
    _ns = 1;
  }
}
template <typename... T>
void out(const T&... _) {
  (_p(_), ...);
}
int ii() {
  int _;
  cin >> _;
  return _;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  struct edge {
    int from;
    int to;
    int w;
  };
  int n = ii();
  vector<pair<int, int>> black;
  vector<pair<int, int>> white;
  vector<edge> ans;
  for (int i = 0; i < n; i++) {
    int clr = ii();
    int w = ii();
    if (clr == 0)
      black.emplace_back(make_pair(i + 1, w));
    else
      white.emplace_back(make_pair(i + 1, w));
  }
  auto b = black.begin();
  auto w = white.begin();
  for (int i = 0; i < n - 1; i++) {
    int bb = b->second;
    int ww = w->second;
    int rem = min(bb, ww);
    ans.emplace_back(edge{b->first, w->first, rem});
    b->second -= rem;
    w->second -= rem;
    if (bb < ww) {
      b++;
    } else if (bb > ww) {
      w++;
    } else {
      if (distance(b, black.end()) > 1) {
        b++;
      } else
        w++;
    }
  }
  for (auto el : ans) {
    out(el.from, el.to, el.w, nl);
  }
  return 0;
}
