#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, c, sV;
  queue<pair<int, int> > whites;
  queue<pair<int, int> > blacks;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c >> sV;
    if (c) {
      whites.push(make_pair(i + 1, sV));
    } else {
      blacks.push(make_pair(i + 1, sV));
    }
  }
  for (int edge = 1; edge < n; ++edge) {
    pair<int, int> w = whites.front();
    whites.pop();
    pair<int, int> b = blacks.front();
    blacks.pop();
    if (w.second > b.second ||
        (w.second == b.second && whites.size() <= blacks.size())) {
      cout << w.first << ' ' << b.first << ' ' << b.second << '\n';
      w.second -= b.second;
      whites.push(w);
    } else {
      cout << w.first << ' ' << b.first << ' ' << w.second << '\n';
      b.second -= w.second;
      blacks.push(b);
    }
  }
}
