#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long i, x, y;
  vector<pair<long long, long long>> zr, on;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    if (x == 0) {
      zr.push_back(make_pair(y, i));
    } else {
      on.push_back(make_pair(y, i));
    }
  }
  sort(zr.begin(), zr.end());
  sort(on.begin(), on.end());
  vector<pair<long long, pair<long long, long long>>> ans;
  long long j = 0;
  i = 0;
  while (i < zr.size() && j < on.size()) {
    long long mn = min(zr[i].first, on[j].first);
    ans.push_back(make_pair(zr[i].second, make_pair(on[j].second, mn)));
    zr[i].first -= mn;
    on[j].first -= mn;
    if (zr[i].first == 0 && on[j].first == 0) {
      if (i + 1 < zr.size()) {
        i++;
      } else {
        j++;
      }
    } else if (zr[i].first > 0) {
      j++;
    } else if (on[j].first > 0) {
      i++;
    } else {
      j++;
    }
  }
  for (i = 0; i < n - 1; i++) {
    cout << ans[i].first << " " << ans[i].second.first << " "
         << ans[i].second.second << '\n';
  }
}
